在Linq-to-Nhibernate中,是否可以在.Select()之后使用.Fetch()? [英] In Linq-to-Nhibernate, is it possible to use .Fetch() after a .Select()?
本文介绍了在Linq-to-Nhibernate中,是否可以在.Select()之后使用.Fetch()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的对象A包含对对象B的多对一引用,而对象B包含对象C的一对多集合,请考虑以下查询:
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();
我想做与此类似的事情,但是我不断使用此代码获取空引用异常.是否有偷偷摸摸的技巧来实现这种查询并获取一堆Object B集合,还是不可能?
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?
谢谢!
推荐答案
您可以指定Fetch before来加载所有A,B,C,然后选择Bs
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();
这篇关于在Linq-to-Nhibernate中,是否可以在.Select()之后使用.Fetch()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文