NHibernate 3.在QueryOver中 [英] NHibernate 3. Alternatives to "ThenFetch" in QueryOver

查看:94
本文介绍了NHibernate 3.在QueryOver中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将NHibernate 3.0与LINQ提供程序和QueryOver一起使用.有时我想急于加载相关数据,LINQ和QueryOver中都提供了"Fetch"方法来进行救援.现在,我有一个特殊的场景,我希望不直接在第二层上加载属性,例如:

I'm using NHibernate 3.0 with both the LINQ provider and QueryOver. Sometimes I want to eager load related data, and there comes the method "Fetch" to the rescue, both in LINQ and QueryOver. Now I have a special scenario where I want to eager load a property not directly on the second level, like:

Foo f = ...;
f.A.B.C

使用LINQ没问题,因为您可以使用"ThenFetch"方法链接"获取,例如:

with LINQ there's no problem, as you can "chain" fetches with the method "ThenFetch", like:

var result = Session.Query<Foo>().Fetch(a => a.A).ThenFetch(b => b.B).ThenFetch(c => c.C).ToList();

在QueryOver中没有这种方法,那么如何获得相同的结果?

In QueryOver there's no such method, so how can I achieve the same result?

提前谢谢.

推荐答案

我实际上设法使用两种不同的方法解决了这个问题:

I actually managed to solve this problem using two different approaches:

方法一:

Session.QueryOver<Foo>().Fetch(x => x.A).Fetch(x => x.A.B).Fetch(x => x.A.B.C)

方法二:

A a = null;
B b = null;
C c = null;

Session.QueryOver<Foo>()
    .JoinAlias(x => x.A, () => a)
    .JoinAlias(() => a.B, () => b)
    .JoinAlias(() => b.C, () => c)

两者都可以工作(尽管我不确定,其中一个是否生成了内部",而另一个生成了外部").

Both work (altough I'm not exactly sure if one of them generated "inner" and the other one "outer" joins).

这篇关于NHibernate 3.在QueryOver中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆