Nhibernate LINQ query with null Where condition

So today I was trying to profile a query and for the life of me I could not see the query in the profiler.  Simple queries where working fine:

Session.Get<User>(123); // I could see the SQL in the profiler.

Session.Query<User>().Where(u => u.thing == someVar) // I was not seeing this in the profiler.

Come to find out, "someVar" was null.  OMG.  Wow.  It's kind of like trying to run this SQL

select u.*
from user
where 1=0

There's pretty much no point in running that query and I guess LINQ to NHibernate thought the same thing!

This happened because someVar was coming from config.  The config file for my unit test was missing the variable, so it was null.  Fun times.

OK, so I fixed that problem and it turned out not to be it.  My queries from the unit test kept returning empty IEnumerables.  So I come to find out that the Fluent Nhibernate Models I am using are special models that are not in the same namespace as the majority of our models.  I had to add the models to the NHibernate Config code and NOW the LINQ queries are working.


Comments

Popular Posts