Suggested reading: http://ayende.com/Blog/archive/2009/09/03/answer-the-lazy-loaded-inheritance-many-to-one-association-orm.aspx
<http://ayende.com/Blog/archive/2009/09/03/answer-the-lazy-loaded-inheritance-many-to-one-association-orm.aspx>Now, there IS a way of getting the underlying type of a superclass proxy: var actualShape = Session.GetSessionImplementation().PersistenceContext. Unproxy(s); if (actualShape is Circle) ... However, that's just a hack. Your should design your classes' behavior to avoid having to cast them. More suggested reading: http://en.wikipedia.org/wiki/Strategy_pattern <http://en.wikipedia.org/wiki/Strategy_pattern> http://en.wikipedia.org/wiki/Liskov_substitution_principle Diego On Mon, Jun 7, 2010 at 13:10, NickNamer <[email protected]> wrote: > I have an abstract base class 'Shape' that has a subclass 'Circle', > 'Square'. All are mapped to the same table using > DiscriminateSubclssesOnColumn. > > I want to retrieve a Shape from the datastore and then check the type > of the shape but nhibernate always maps to the base class 'Shape' e.g. > > Shape s = session.Get<Shape>(1); > > if (s is Circle){ > //Do Whatever... > } > else if (s is Square) > { > //Do Something > } > //None are detected > and > s.GetType() always returns Shape - which is an abstract class > > Is there a way to get the underlying class type? > > > -- > 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.
