NHibernate 3. “ThenFetch"的替代方案在 QueryOver 中 [英] NHibernate 3. Alternatives to "ThenFetch" in QueryOver

查看:16
本文介绍了NHibernate 3. “ThenFetch"的替代方案在 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. “ThenFetch"的替代方案在 QueryOver 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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