当我在select中的同一个表的引用和我的where子句时,linq到Nhibernate会生成两个连接,一个连接select,一个连接where。即Linq到NHibernate生成多个连接到同一个表
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'
有没有一种方法来构造查询得到这个? 重要吗?
你怎么设置你的映射文件?你有没有设置cascade选项为false? – cpoDesign 2011-04-30 02:27:45