Yes I know that a Dog is not a Cat.
Let say I add another type that inherits Person:
public class Client: Person{...}
or
public class Employee:Person{...}So I have a Person that is an employee in a company, but the same person is a client in the same company he is working for. How to model this type o relation? On Aug 6, 6:57 pm, Fabio Maulo <[email protected]> wrote: > That is not a classic table-per-subclass. > As said that is a misunderstanding of OOP. > A Dog can be a Cat. > > In you case a Person can assume more than one roles (as usual when you work > with a class named Person) > > > > > > On Fri, Aug 6, 2010 at 1:37 PM, Luka <[email protected]> wrote: > > I see the point, but how to solve this? Because this is the classic > > Table per subclass and NHibernate is supposed to support this type of > > inheritance. (by the book NHibernate in action) > > > On Aug 6, 6: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%252bunsubscr...@googlegroup > > s.com>> > > > > . > > > > 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. > > -- > 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]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
