2

How determine in C# if an Object is the original object or a dynamic proxy of the original object?

I run into this need playing with nhibernate.

skolima
  • 31,963
  • 27
  • 115
  • 151
Vigj
  • 71
  • 4
  • 7

1 Answers1

3

Answer is here in a previous question.

You can detect if a class is a NHibernate proxy by casting it to (unsurprisingly) INHibernateProxy.

If you need to get the underlying "real" object, use:

Session.GetSessionImplementation().PersistenceContext.Unproxy(proxiedObject) You don't need to test for proxies to call Unproxy; it returns the original parameter if it's not a proxy.

Community
  • 1
  • 1
Serapth
  • 7,122
  • 4
  • 31
  • 39