【问题标题】:Nhibernate QueryOver use alias in Eager FetchNhibernate QueryOver 在 Eager Fetch 中使用别名
【发布时间】:2012-08-28 14:11:29
【问题描述】:

我正在尝试让 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 语句是不同的。

【问题讨论】:

  • 为什么需要使用来自JoinAlias的别名?

标签: nhibernate queryover


【解决方案1】:

试试这样的:

B b = null;

QueryOver<A>()
   .Fetch(x => x.B).Eager
   .JoinAlias(x => x.B, () => b, JoinType.LeftOuterJoin);

【讨论】:

【解决方案2】:

您可以只使用连接,Fetch 无论如何都会解析为 INNER JOIN LEFT OUTER JOIN

QueryOver<A>() 
    .JoinAlias(x => x.B, () => bAlias) 
    .Where(() => bAlias.Surname == "Smith") 
    .Fetch(x => x.B).Eager 
    .JoinQueryOver(() => bAlias.C)

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-06
  • 2015-01-09
  • 2011-09-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多