我正在尝试使用NHibernate.Linq的NHibernate Session.Query,并将其投影为匿名类型,但是当我检查references属性为null时,NHibernate添加了从主表和每个联接中选择每一列的列表。>
Linq查询:
_session.Query<Allocation>()
.Select(x => new
{
Id = x.Id,
OwnerId = x.Owner != null ? x.Owner.Id : 0
})
.FirstOrDefault();
NHibernate SQL结果:
SELECT allocation0_.id AS col_0_0_,
contractor1_.id AS col_1_0_,
allocation0_.owner_id AS col_2_0_,
contractor1_.id AS Id1_2_,
contractor1_.symbol AS symbol2_2_,
contractor1_."name" AS name3_2_,
contractor1_.is_active AS is4_2_
FROM allocation allocation0_
LEFT OUTER JOIN contractor contractor1_
ON allocation0_.owner_id = contractor1_.id
LIMIT 1
我知道可以通过使用QueryOver和投影列表来实现,但是我想知道为什么这种方式会生成错误的SQL结果