I have a base class DomainObject
for all my business objects I am using with NHibernate. It contains the Id
property.
public abstract
You can get the real type of a proxy with:
NHibernateUtil.GetClass(x);
or you can add a method to DomainObject
like:
public virtual Type GetTypeUnproxied()
{
return GetType();
}
Which is really slick and doesn't depend directly on NHibernate.
Alternatively, one can approach the problem by saying you need to get the true object, rather than the proxy, which, if the session is handy, can be done with:
session.PersistenceContext.Unproxy(x);
As mentioned in another answer, if you're trying to implement equals it would be a good idea to check out the Sharp architecture implementation of Equals.