Is there a way to make nhibernate return my class instead of its proxy class? I dont mind if it's not lazy or cant be updated.
You can unproxy class with this code
session.PersistenceContext.Unproxy(proxiedInstance)
You should define this in your mapping, by defining lazy="false"
<class name="MyEntity" table="MyTable" lazy="false">
</class>
You can use following code to get real object
InstanceType instance;
if (proxiedInstance is INHibernateProxy)
{
var lazyInitialiser = ((INHibernateProxy)proxiedInstance).HibernateLazyInitializer;
instance = (InstanceType)lazyInitialiser.GetImplementation();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With