What I think he is trying to do is more like cat is an animal kitten is a cat
but you can only subclass so far on a path like that, not expand that to 140 potential subclasses from his example a is a supertype b is a type of a c is a type of b ... It is still a better design to work out what the real world classes are, each with their own identifiers and their own properties and if there is still a valid inheritance or association structure then map those inheritances and associations. NHibernate will not manage the structure you are creating to avoid building a proper db design. If you really need such a structure you would be better advised to use a noSQL db such as RavenDB. John Davidson On Fri, Oct 22, 2010 at 12:23 PM, Jason Meckley <[email protected]>wrote: > to expand on what fabio is stating... > what you want isn't possible. inheritance mapping works on type. once > "set" it doesn't change. the classic example of animal, cat and dog. > cat is an animal > dog is an animal > dog is not a cat (& vice verse) > > once you have a dog you cannot change it to a cat. > > if you have an object that can be A, B, or C depending on the context > of the work flow, then you will need to manage that in code. > > On Oct 22, 11:40 am, Fabio Maulo <[email protected]> wrote: > > A row in the DB is the representation of the state of one object: which > one? > > > > -- > > Fabio Maulo > > > > El 22/10/2010, a las 12:05, Brian Chavez <[email protected]> > escribió: > > > > Hi Fabio, > > > > Row 5 can be A, B, and C, depending on which one I'm requesting. > > > > The class hierarchy at A implements Id. > > > > class A{ > > int Id{get;set;} > > AProperty{get;set;} //Mapped to ColumnA in Table 1 > > > > } > > > > class B : A { > > BProperty{get;set;} //Mapped to ColumnB in Table 1 > > > > } > > > > class C : B { > > CProperty{get;set;} //Mapped to ColumnC in Table 1 > > > > } > > > > B and C only map extra properties which are column projections. > > > > CreateCriteria(typeof(A)).Add(Expression.Eq("Id", > > 5)).UniqueResult<A>() > > CreateCriteria(typeof(C)).Add(Expression.Eq("Id", > > 5)).UniqueResult<C>() > > > > The Database Identity of A and C are the same. > > The only difference is that C includes C.AProperty, C.BProperty, and > > C.CProperty projection. Where as A only has A.AProeprty projection. > > > > Thanks, > > Brian > > > > On Oct 22, 7:54 am, Fabio Maulo <[email protected]> wrote: > > > > A row in the DB is the representation of the state of one object: which > one? > > > > -- > > > > Fabio Maulo > > > > El 22/10/2010, a las 11:40, Brian Chavez <[email protected]> > escribió: > > > > Hi Alan, > > > > Thanks so much for the reply. I'm trying to avoid NHibernate using the > > > > database to determine the type of object. > > > > A single row in Table 1 can be projected into any object in the class > > > > hierarchy. > > > > For example, Row 5 is A, B, or C; depending on which type I'm > > > > requesting. > > > > If I CreateCriteria(typeof(C)), then NHibernate has enough information > > > > to know what type I'm requesting. > > > > I don't want NHibernate to extract type information from the database > > > > (ie: discriminator) because class A, B, and C can all represent any > > > > row in Table 1. > > > > The only difference between A, B, and C classes is the projections of > > > > the columns in the table. > > > > I hope that clarifies my situation. > > > > Any feedback would be appreciated! > > > > -Brian > > > > On Oct 22, 7:13 am, "[email protected]" > > > > <[email protected]> wrote: > > > > You can use formulas as discriminators as opposed to a column. You > > > > obviously have some sort of logic that determines the object type? > > > > On Oct 22, 9:02 am, Brian Chavez <[email protected]> wrote: > > > > Hello. > > > > Problem: > > > > I have 1 very large table of columns. > > > > I have a class hierarchy that represents different projections of the > > > > columns of this table. > > > > For example: > > > > class A{ > > > > AProperty{get;set;} //Mapped to ColumnA in Table 1 > > > > } > > > > class B : A { > > > > BProperty{get;set;} //Mapped to ColumnB in Table 1 > > > > } > > > > class C : B { > > > > CProperty{get;set;} > > > > } > > > > When I ask NHibernate to pull C, I expect to see C.AProperty, > > > > C.BProperty, and C.CProperty. > > > > Essentially, this class hierarchy represents different scoped > > > > projected views of the *same* table. > > > > How do I do this in hbm.xml mapping files without adding discriminator > > > > values? > > > > I've tried to use multiple <union-subclass> attributes and map to the > > > > same table, but NH throws an exception: > > > > --> NHibernate.DuplicateMappingException : Duplicate table mapping > > > > Table 1 > > > > Any ideas? > > > > Thanks, > > > > Brian > > > > -- > > > > 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 athttp:// > > 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 athttp:// > 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.
