在 Linq-to-Nhibernate 中,是否可以在 .Select() 之后使用 .Fetch()?

发布于 2024-12-21 02:16:15 字数 355 浏览 1 评论 0原文

如果我有一个对象 A,其中包含对对象 B 的多对一引用,其中对象 B 包含对象 C 的一对多集合...请考虑以下查询:

IQueryable<A> query = getIQueryableSomehow();

List<B> resultList = query.Where(A => A.whatever == something).Select(A => A.B).Fetch(B => B.C).ToList();

我想做与此类似的操作,但我不断收到此代码的空引用异常。是否有一个偷偷摸摸的技巧来实现这种查询并获取一堆对象 B 集合,或者这是不可能的?

谢谢!

If I had an Object A that contained a many-to-one reference to Object B, where Object B contained a one-to-many collection of Object C... consider the following query:

IQueryable<A> query = getIQueryableSomehow();

List<B> resultList = query.Where(A => A.whatever == something).Select(A => A.B).Fetch(B => B.C).ToList();

I want to do something similar to this, but I keep getting a null reference exception with this code. Is there a sneaky trick to achieve this kind of query AND fetch a bunch of Object B collections, or is it impossible?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慈悲佛祖 2024-12-28 02:16:15

可以指定 Fetch before 加载所有 A,B,C 然后选择 B

List<B> resultList = query
    .Where(A => A.whatever == something)
    .Fetch(A => A.B).ThenFetch(B => B.C)
    .Select(A => A.B)
    .ToList();

you can specify Fetch before to load all A,B,C and then select the Bs

List<B> resultList = query
    .Where(A => A.whatever == something)
    .Fetch(A => A.B).ThenFetch(B => B.C)
    .Select(A => A.B)
    .ToList();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文