NHibernate Pitfalls: Querying Unmapped Classes
This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.
The idea for this post came from Kelly Brownsberger (@kbrowns).
When asking NHibernate to query an unmapped class, different query APIs have different behaviors:
- LINQ, Query Over and Criteria silently ignore the query and return no results;
- HQL, ISession.Get<T> and ISession.Load<T> fail with an exception.
So, be careful, because, if, for instance, you are using conventional mapping (see here and here), if you do some mistake, your entity might not be mapped.