Proper way of doing type checking on entities?

19 views
Skip to first unread message

Joseph Lam

unread,
May 15, 2012, 8:55:57 AM5/15/12
to nhu...@googlegroups.com
In .Net there are several ways to perform type checking:
- the 'is' keyword
- Type.IsAssignableFrom()
- Type.IsInstanceOfType()

What confuses me is the proxying in NH which affects things such as myEntity.GetType() (which returns you a proxy type instead of the actual entity type), and depending the lazy loading and proxying configuration, one will see different behaviors in different scenarios. We use the 'is' keyword a lot and it has been working fine with NH 3.0/3.1, but starts to fail in some cases with NH3.2/3.3. It is really frustrating and make upgrades very difficult.

Is there any good documentation around polymorphic behaviors and type checking for NH (especially 3.3)? Or how do people usually do it?

Regards,
Joseph

David Corbin

unread,
May 15, 2012, 2:09:58 PM5/15/12
to nhu...@googlegroups.com
I typically use IsAssignableFrom(...) as it provides the widest coverage.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/1B29IwTfMjMJ.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Asher Newcomer

unread,
May 15, 2012, 2:19:25 PM5/15/12
to nhu...@googlegroups.com
I think in the past I've bubbled up a call to GetType() from a virtual method on my entity. That way it will return the unproxied type even when called on a proxy. I'm fairly sure that still works though I'd need to test it.
Reply all
Reply to author
Forward
0 new messages