我正在使用NHibernate来查询我的数据库,我们正在使用的其中一个字段曾经被映射为可以为空的bool(bool?
)
我们已将其更改为常规bool,由SQL Server位NOT NULL字段支持。
NHibernate仍在生成如下查询:
SELECT count(*) as y0_
FROM mydb.dbo.[Customer] this_
inner join mydb.dbo.[Order] fi1_
on this_.OrderId = fi1_.Id
WHERE (this_.CustomerId = 9625 /* @p0 */
and (this_.Deleted = 0 /* @p1 */
or this_.Deleted is null))
最后一行 - or this_.Deleted is null
- 是不必要的,实际上是通过强制SQL Server进行额外的NULL检查来减慢生成的查询。
如何让NHibernate生成this_.Deleted = 0
并省略NULL检查?