To borrow a phrase from the standard hilo response... Are columns expensive in your country?
Don't worry. Applications usually work best when we let NHibernate do what it wants. - Jason On Fri, Aug 6, 2010 at 11:50 AM, Luka <[email protected]> wrote: > ok, you propose composition over inheritance. > But my teacher has some other properties ie: favoritebook etc.. > and my policeman has other properties too ie: colleague etc. > and if I put all those properties in a single table i get many rows > that contains null in specific columns. > > On Aug 6, 6:34 pm, Jason Meckley <[email protected]> wrote: > > according to you're object hierarchy and NH mapping/database schema a > > person can be either a policeman or a teacher, not both. > > If they can be both you need to change your domain model/db schema to > > allow for this. something like > > > > class person > > { > > IList<Job> Occupations; > > > > } > > > > person table > > id > > name > > > > occupation table > > person id > > job id > > > > Job table > > id > > description > > > > in other words... a person has many jobs. not a person is a job. > > > > On Aug 6, 12:16 pm, Fabio Maulo <[email protected]> wrote: > > > > > > > > > The problem is not the mapping but the concept of OOP. > > > Let me show another case: > > > Animal > > > Dog : Animal > > > Cat : Animal > > > > > In the DB I have an Animal with ID 1 that is a Dog and a Cat. > > > > > On Fri, Aug 6, 2010 at 11:50 AM, James Gregory < > [email protected]>wrote: > > > > > > Please show us your mappings. > > > > > > You should have: > > > > > > ClassMap<Person> > > > > SubclassMap<Teacher> > > > > SubclassMap<Policeman> > > > > > > On Aug 6, 3:32 pm, Luka <[email protected]> wrote: > > > > > ups my error! > > > > > > > I have this problem: > > > > > public class Person:DomainBase<Person,int> > > > > > { > > > > > public string Name; > > > > > > > } > > > > > > > public class Teacher: Person > > > > > {... > > > > > > > } > > > > > > > public class Policeman:Person > > > > > {... > > > > > > > } > > > > > > > All classes are mapped using fluent nhibernate. > > > > > The inheritance is mapped by: SubClassMap<Person>. > > > > > > > In code I am doing this: > > > > > IPersonRepository rep = > > > > > ObjectFactory.GetInstance<IPersonRepository>(); > > > > > var teachers = rep.GetAllTeachers(); > > > > > var policemans = rep.GetAllPolicemans(); > > > > > > > The error I am getting is this: > > > > > > > Object with id: 1 was not of the specified subclass: Policeman > > > > > (loading object was of wrong class [Teacher]). > > > > > > > in the database I have i person with ID 1 that is a teacher and a > > > > > policeman. > > > > > > > How to solve this problem? > > > > > > -- > > > > 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]> > <nhusers%[email protected]<nhusers%[email protected]>> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/nhusers?hl=en. > > > > > -- > > > Fabio Maulo > > -- > 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.
