Categories
Uncategorized

NHibernate doesn’t stop you when you try to query something it does not know about

I recently upgraded a system from using NHibernate 4 to using NHibernate 5. The upgrade itself was uneventful. Apart from a minor interface change in IUserType, everything kind of went smoothly. As soon as everything compiled, I started the system and… nothing happened.

There were no crashes, there were no exceptions, but all queries returned zero results. Strange.

I fired up NHProf. No SQL showed up, no queries were fired against the database. Yet I can step through my data-access code without hitting exceptions.

As it turns out, NHibernate does not stop you (by throwing an exception) from querying entities it does not know how to query. Instead, it just returns an empty collection of the type you’re attempting to query. I wasn’t expecting that.

So if you ever run into this issue, make sure to check whether you have loaded your class mappings.