【发布时间】:2012-03-22 19:00:06
【问题描述】:
我有以下 Nhibernate LINQ 查询:
var query = from c in session.Query<Customer>()
where
c.EmailAddress == customer.EmailAddress ||
(
c.Address1 == customer.Address1 &&
c.City == customer.City &&
c.State == customer.State &&
c.Postal == customer.Postal &&
c.FirstName == customer.FirstName &&
c.LastName == customer.LastName
)
select c;
我希望生成的 SQL 语句如下所示:
select
...
from
dbo.Customers customer0_
where
customer0_.EmailAddress=@p0 or
(
customer0_.Address1=@p1
and customer0_.City=@p2
and customer0_.State=@p3
and customer0_.Postal=@p4
and customer0_.FirstName=@p5
and customer0_.LastName=@p6;
)
但我从调试日志中看到的是:
select
...
from
dbo.Customers customer0_
where
customer0_.EmailAddress=@p0
or customer0_.Address1=@p1
and customer0_.City=@p2
and customer0_.State=@p3
and customer0_.Postal=@p4
and customer0_.FirstName=@p5
and customer0_.LastName=@p6;
请注意,where 子句的地址部分没有分组。这是故意的吗?我应该以不同的方式格式化我的查询,还是这是一个错误?
【问题讨论】:
-
我怀疑您需要升级到 3.2(或来自主干的最新版本),因为 3.1 linq 功能不完整。
-
带有此代码的程序集引用的是 3.1(附带 Fluent Nhibernate nuget 包),但主项目引用的是 3.2,带有绑定重定向,所以实际的实时代码应该使用 3.2,没有?
标签: nhibernate