当我在 select 和 where 子句中引用同一个表时,linq to Nhibernate 会生成两个连接,一个用于 select,一个用于 where。 IE。
from child in Session.Query<Child>()
where child.Parent.Name == "Bob"
select new Info
{
ParentAge = child.Parent.Age,
ChildName = child.Name
};
生成如下 SQL:
Select this_.Name,
parent1.Age
From Child this_
left join Parent parent1 on child.ParentId = parent1.Id,
Parent parent2
Where child.ParentId = parent2.Id and parent2.Name = 'Bob'
我本以为我应该让 SQL 更像:
Select this_.Name,
parent1.Age
From Child this_
inner join Parent parent1 on child.ParentId = parent1.Id
Where parent1.Name = 'Bob'
有没有办法构建查询来得到这个?
有关系吗?
您可以使用透明标识符来阻止 NHibernate 执行此操作,以便您的查询如下所示:
from child in Session.Query<Child>()
let p = child.Parent
where p.Name == "Bob"
select new Info {
ParentAge = p.Age,
ChildName = child.Name
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)