Hi everyone. No one has answered my question so I'll ask it again. I hope somebody can help me out on this one.
Lets suppose I have a Base class and a Derived class, using table per subclass inheritance strategy. Now, lets suppose I've added a record in the Base table, and later I want to add a record in the Derived table related to the previously added record in the Base table. Let my try to explain this using my previous example: first of all, instead of having said "User" and "UserAppN" tables, I should have used "UserProfile" and "UserProfileAppN" tables, since this has nothing to do with membership. Having clarified that, this is my current architecture: I have a base "UserProfile" class containing data and operations used by all applications, and specific "UserProfileAppN" class per each of my applications, containing data and operations used by that specific app. This "UserProfileAppN" classes derive from "UserProfile". The reason I chose this is because I don't want to be changing my base "UserProfile" class everytime a new application with different needs appears. I know I can't change a "UserProfile" object to a "UserProfileAppN" object in code; I can't cast a "UserProfile" to a "UserProfileApp1", for example. But, in my database, I already have a "UserProfile" record, so, what I want to do, is to create a "UserProfileApp1" record related to this "UserProfile" record, and later create a "UserProfileApp2" record also related to the same "UserProfile" record. Is there a way to do this with NHibernate? Thanks in advance, I really appreciate the time you dedicate to NHibernate and the time you dedicate to help out all the noobs like me. On Tue, Aug 31, 2010 at 10:31, Yorch <[email protected]> wrote: > Yeah, I already have those relationships you mention regarding users, > applications and roles. > > I should probably have explained with a little more detail my need for > those UserAppN tables. They are needed since every application will need > somewhat different data. In some applications I need to know the e-mail of > the person, in others I need to have a photo, in others I need their > computer name, etc... I could probably put all that information into a > single table and use another inheritance strategy, but I'm not sure if it'll > help me solve my problem. What I'm trying to accomplish is to take advantage > of polymorphism so I won't have code like > if(string.IsNullOrEmpty(user.Email)) ... to find out the 'type' of user and > its operations. > > I think I'll be going down the path you mention, having several one-to-one > relationships through composition instead of inheritance, but I was > wondering if there was a way to insert the information of those UserAppN > tables and relate them to an existing User, without having to set ID's > directly. > > > On Tue, Aug 31, 2010 at 09:49, Diego Mijelshon <[email protected]>wrote: > >> What you have there is not inheritance, it's definitely a has-a (or >> has-many) relationship. >> Perhaps even the most studied case of that kind of relationship. >> In this case, a User has (or "corresponds to") zero, one or many >> applications (or roles), so that should be the model. >> You probably don't even need those UserAppN tables (if you do, then it >> might be several one-to-one relationships) >> >> Diego >> >> >> On Tue, Aug 31, 2010 at 12:50, Yorch <[email protected]> wrote: >> >>> Good afternoon, >>> >>> I'm facing a bit of a problem here regarding inheritance in NHibernate. >>> >>> I have an architecture where there's an User base class and a several >>> derived user classes for different applications that are accessing the >>> database (UserApp1, UserApp2, ..., UserAppN). I'm using the Table per >>> subclass strategy, so it's a one-to-one association between the User table >>> and each of the UserAppN tables. >>> >>> What I want to do is to first create and persist the information in the >>> User class, and sometime after that create the information for each of the >>> applications, depending on whether the user has access >>> to it or not. The problem I'm facing is that I don't know the correct way >>> to create a UserAppN from a User. I've been googling this for a while and >>> haven't been able to find anything, so I hope you can help me. >>> >>> So, my question is this: how can I create a UserAppN from an already >>> existent User, in code and in the database, and have them related? I'm about >>> to "favor composition over inheritance" here, having a User instance in each >>> of the UserAppN classes, but I'd also like to know if there's a way to solve >>> my problem with inheritance. >>> >>> Thanks in advance. >>> >>> Jorge Vargas. >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "nhusers" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]<nhusers%[email protected]> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/nhusers?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "nhusers" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<nhusers%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/nhusers?hl=en. >> > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
