I use NHibernate to query my database, and one of the fields we work with was used to match nullable bool ( bool?
)
We changed it to a regular bool, supported by the SQL NOT NOT NULL field.
NHibernate still generates queries that look like this:
SELECT count(*) as y0_ FROM mydb.dbo.[Customer] this_ inner join mydb.dbo.[Order] fi1_ on this_.OrderId = fi1_.Id WHERE (this_.CustomerId = 9625 and (this_.Deleted = 0 or this_.Deleted is null))
This last line — or this_.Deleted is null
— is unnecessary and actually slows down the resulting query, causing SQL Server to perform additional NULL checks.
How can I get NHibernate to create only this_.Deleted = 0
and leave the NULL check?
source share