To get an โunforgivenโ type, you can add a method like this in FooBase:
public virtual Type GetTypeUnproxied() { return GetType(); }
When this method is called in the proxy server, the type of the base object is returned.
However, from your description, it seems that you are trying to do this outside of an NHibernate session, and this will not work with this strategy either. To call any method in the proxy server where the call is proxied to the base object, it must be created, and this can only happen in the NHibernate session, since the actual type of the object is stored in the database (in the discriminator column for the table, the inheritance strategy of the hierarchy-class- hierarchy). Therefore, I assume that you need to make sure that the proxy is initialized before the session is closed, if you need to check the type later.
If the reason for lazy loading the Bar-> FooBase relationship is because FooBase (or a derived type) can contain large amounts of data, and you are using NHibernate 3, you can use lazy properties .
source share