Forget about the Role information. I am just assigning FirstName and LastName to a Teacher object. Roles and UserRoles will be different table since one person can have many roles.
How can I just insert the Teacher's "FirstName" and "LastName" into the Users table? On Aug 13, 4:53 pm, James Gregory <[email protected]> wrote: > You need another column in your Users table to tell NHibernate what each row > is. How else is it supposed to be able to tell what entity each row is? > > > > On Thu, Aug 13, 2009 at 10:52 PM, AzamSharp <[email protected]> wrote: > > > No I don't have a discriminator column. I only have a Users table > > which has the following fields: > > > UserId, FirstName and LastName. > > > There is not even a Teacher table or a Student table. Teacher and > > Student both uses the Users table to store the information. > > > On Aug 13, 4:48 pm, James Gregory <[email protected]> wrote: > > > Do you have a column name called discriminator? > > > You need a column in your table which tells NHibernate what the entity a > > row > > > represents, that is what you put in the DiscriminateSubClassesOnColumn > > call. > > > > On Thu, Aug 13, 2009 at 10:46 PM, AzamSharp <[email protected]> wrote: > > > > > Now it is throwing invalid column name discriminator: > > > > > public class UserMap : ClassMap<User> > > > > { > > > > public UserMap() > > > > { > > > > Id(x => x.Id).ColumnName("UserId"); > > > > Map(x => x.FirstName); > > > > Map(x => x.LastName); > > > > WithTable("Users"); > > > > > DiscriminateSubClassesOnColumn("discriminator") > > > > .SubClass<Teacher>(m => { }); > > > > > } > > > > } > > > > > On Aug 13, 4:45 pm, James Gregory <[email protected]> wrote: > > > > > Then just leave the mapping empty! > > > > > SubClass<Teacher>(m => {}); > > > > > > On Thu, Aug 13, 2009 at 10:44 PM, AzamSharp <[email protected]> > > wrote: > > > > > > > Teacher does not have anything extra. It only uses the inherited > > > > > > fields from the User class! > > > > > > > On Aug 13, 4:43 pm, James Gregory <[email protected]> wrote: > > > > > > > No you don't need to remap them. Just map anything that *only* > > > > appears on > > > > > > > Teacher inside the SubClass<Teacher> call. > > > > > > > > On Thu, Aug 13, 2009 at 10:42 PM, AzamSharp <[email protected] > > > > > wrote: > > > > > > > > > Here is my code: > > > > > > > > > public class UserMap : ClassMap<User> > > > > > > > > { > > > > > > > > public UserMap() > > > > > > > > { > > > > > > > > Id(x => x.Id).ColumnName("UserId"); > > > > > > > > Map(x => x.FirstName); > > > > > > > > Map(x => x.LastName); > > > > > > > > WithTable("Users"); > > > > > > > > > DiscriminateSubClassesOnColumn("discriminator") > > > > > > > > .SubClass<Teacher>( > > > > > > > > > m => > > > > > > > > { > > > > > > > > // do I have to define the mappings > > again > > > > for > > > > > > > > teacher. teacher inherit from User so it should map > > "FirstName", > > > > > > > > "LastName" and "Id" automatically! > > > > > > > > } > > > > > > > > > ); > > > > > > > > > } > > > > > > > > } > > > > > > > > > On Aug 13, 4:38 pm, James Gregory <[email protected]> > > wrote: > > > > > > > > > You haven't mapped your teacher. > > > > > > > > > public class UserMap : ClassMap<User> > > > > > > > > > { > > > > > > > > > public UserMap() > > > > > > > > > { > > > > > > > > > Id(x => x.Id); > > > > > > > > > Map(x => x.PropertyInUser); > > > > > > > > > > // > > > > > > > > > // mappings on User and all subclasses here > > > > > > > > > // > > > > > > > > > > DiscriminateSubClassesOnColumn("discriminator") > > > > > > > > > .SubClass<Teacher>(m => > > > > > > > > > { > > > > > > > > > // any mappings ONLY on teacher here > > > > > > > > > }); > > > > > > > > > } > > > > > > > > > > } > > > > > > > > > On Thu, Aug 13, 2009 at 10:34 PM, AzamSharp < > > [email protected] > > > > > > > wrote: > > > > > > > > > > > I have a scenario where I have a base class called "User" > > and I > > > > > > have > > > > > > > > > > inherited classed called "Teacher" and "Student". I have > > define > > > > > > some > > > > > > > > > > properties in the User class which are also used in the > > Teacher > > > > and > > > > > > > > > > Student through inheritance. I have defined the UserMap > > with > > > > all > > > > > > the > > > > > > > > > > mappings. But it throws error when I try to save the > > Teacher > > > > saying > > > > > > > > > > "Persister is not defined". > > > > > > > > > > > Thanks, > > > > > > > > > > Azam > > > > > > > > > > > On Aug 13, 4:29 pm, James Gregory <[email protected] > > > > > wrote: > > > > > > > > > > > DiscriminateSubClassOnColumn is only to be used for the > > > > > > discriminator > > > > > > > > > > > column, the column in your table that dictates what > > entity > > > > type > > > > > > the > > > > > > > > row > > > > > > > > > > > contains. > > > > > > > > > > > All other properties are mapped normally. > > > > > > > > > > > > On Thu, Aug 13, 2009 at 10:10 PM, AzamSharp < > > > > [email protected] > > > > > > > > > wrote: > > > > > > > > > > > > > Hi, > > > > > > > > > > > > > I just looked at the syntax for > > > > > > DiscriminateSubClassesOnColumn() > > > > > > > > which > > > > > > > > > > > > is little weird but anyway!! > > > > > > > > > > > > > It seems like I have to create a > > > > DiscriminateSubClassesOnColumn > > > > > > for > > > > > > > > > > > > every column that is being used in the Base class. Is > > that > > > > > > right? > > > > > > > > That > > > > > > > > > > > > will be a disaster for me since I have several fields > > in > > > > the > > > > > > sub > > > > > > > > > > > > classes which are inherited from the base class. > > > > > > > > > > > > > Thanks, > > > > > > > > > > > > Azam > > > > > > > > > > > > > On Aug 12, 9:55 am, Hudson Akridge < > > > > [email protected]> > > > > > > > > wrote: > > > > > > > > > > > > > Definitely. :) Think of it this way, how else would > > NH > > > > know > > > > > > about > > > > > > > > > > your > > > > > > > > > > > > > Teacher, or more importantly, how to rehydrate a > > Teacher > > > > > > instead > > > > > > > > of a > > > > > > > > > > > > User > > > > > > > > > > > > > whenever you retrieve information from that row. It's > > > > that > > > > > > > > > > discriminator, > > > > > > > > > > > > > when you persist a Teacher, it needs to know how to > > flag > > > > it > > > > > > as a > > > > > > > > > > Teacher > > > > > > > > > > > > > class, and separate it from a User class. In order > > for it > > > > to > > > > > > do > > > > > > > > that, > > > > > > > > > > you > > > > > > > > > > > > > have to tell it what the Teacher's discriminator is > > going > > > > to > > > > > > be, > > > > > > > > and > > > > > > > > > > tie > > > > > > > > > > > > it > > > > > > > > > > > > > to the Teacher type. > > > > > > > > > > > > > > On Wed, Aug 12, 2009 at 9:53 AM, AzamSharp < > > > > > > [email protected]> > > > > > > > > > > wrote: > > > > > > > > > > > > > > > What is the Teacher does not exposes any additional > > > > > > attributes > > > > > > > > and > > > > > > > > > > is > > > > > > > > > > > > > > same as the User class? Do I still have to use the > > > > > > > > > > > > > > DiscriminateSubclasses in the UserMap? > > > > > > > > > > > > > > > Thanks, > > > > > > > > > > > > > > Azam > > > > > > > > > > > > > > > On Aug 12, 9:47 am, Hudson Akridge < > > > > > > [email protected]> > > > > > > > > > > wrote: > > > > > > > > > > > > > > > Even with no specific attributes on Teacher > > (which if > > > > all > > > > > > > > you've > > > > > > > > > > got > > > > > > > > > > > > is > > > > > > > > > > > > > > > different behavior, you may want to look at the > > State > > > > > > > > pattern), > > > > > > > > > > you > > > > > > > > > > > > still > > > > > > > > > > > > > > > need to register Teacher as a subclass with > > FNH/NH, > > > > and > > > > > > you > > > > > > > > do > > > > > > > > > > that > > > > > > > > > > > > by > > > > > > > > > > > > > > > declaring it on the DiscriminateSubclasses FNH > > method > > > > in > > > > > > your > > > > > > > > > > > > UserMap. > > > > > > > > > > > > > > > > On Wed, Aug 12, 2009 at 9:45 AM, AzamSharp < > > > > > > > > [email protected]> > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > > > > Thanks for the reply! > > > > > > > > > > > > > > > > > Teacher inherits from User class and there is > > only > > > > > > Users > > > > > > > > table > > > > > > > > > > in > > > > > > > > > > > > the > > > > > > > > > > > > > > > > database. > > > > > > > > > > > > > > > > > User class has a UserMap which defines the > > mapping > > > > for > > > > > > the > > > > > > > > > > User. > > > > > > > > > > > > > > > > Teacher does not define any mapping. If I don't > > > > have > > > > > > any > > > > > > > > > > mapping > > > > > > > > > > > > for > > > > > > > > > > > > > > > > Teacher then it gives error for "persister not > > > > > > defined". > > > > > > > > > > > > > > > > > Thanks, > > > > > > > > > > > > > > > > Azam > > > > > > > > > > > > > > > > > On Aug 12, 9:38 am, James Gregory < > > > > > > [email protected] > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > I was actually referring to what Azam is > > trying > > > > to do > > > > > > :) > > > > > > > > > > > > > > > > > > You should never need to subclass your > > ClassMap. > > > > > > > > > > > > > > > > > > On Wed, Aug 12, 2009 at 3:30 PM, Hudson > > Akridge < > > > > > > > > > > > > > > > > [email protected]>wrote: > > > > > > > > > > > > > > > > > > > Absolutely correct :) I might have > > > > misunderstood > > > > > > what > > > > > > > > the > > > > > > > > > > OP > > > > > > > > > > > > was > > > > > > > > > > > > > > > > asking, I > > > > > > > > > > > > > > > > > > assumed that he wanted to extend the > > mappings > > > > for > > > > > > > > Teacher > > > > > > > > > > from > > > > > > > > > > > > his > > > > > > > > > > > > > > > > UserMap. > > ... > > read more » --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" 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/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---
