当我在我的where子句中选择同一个表时,linq到Nhibernate生成两个连接,一个用于选择,一个用于where.即
from child in Session.Query<Child>()
where child.Parent.Name == "Bob"
select new Info
{
ParentAge = child.Parent.Age,
ChildName = child.Name
};
Run Code Online (Sandbox Code Playgroud)
生成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'
Run Code Online (Sandbox Code Playgroud)
我原本以为我应该更喜欢SQL:
Select this_.Name,
parent1.Age
From Child this_
inner join Parent parent1 on child.ParentId = parent1.Id
Where parent1.Name = 'Bob'
Run Code Online (Sandbox Code Playgroud)
有没有办法构建查询来获得这个?有关系吗?