我试图让 nhibernate 在急切的获取中使用别名。我不确定这可能。
我正在尝试在提取中使用别名(在我的示例中为 bAlias)。
QueryOver<A>()
.JoinAlias(x => x.B, () => bAlias)
.JoinAlias(x => x.B, () => bAlias2)
.Where(() => bAlias2.Surname == "Smith")
.Fetch(() => bAlias).Eager
.Fetch(() => bAlias.C).Eager;
如您所见,提取命令使用 2 个别名,而不是来自 的直接路径。
上面的代码不起作用。有效的代码是
QueryOver<A>()
.JoinAlias(x => x.B, () => bAlias)
.JoinAlias(x => x.B, () => bAlias2)
.Where(() => bAlias2.Surname == "Smith")
.Fetch(x => x.B).Eager
.Fetch(x => x.B.C).Eager;
正如您所看到的,Fetch 语句是不同的。
最佳答案
尝试这样的事情:
B b = null;
QueryOver<A>()
.Fetch(x => x.B).Eager
.JoinAlias(x => x.B, () => b, JoinType.LeftOuterJoin);
关于Nhibernate QueryOver 在 Eager Fetch 中使用别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12161166/