In Linq-to-Nhibernate, is it possible to use .Fetch() after a .Select()?

人走茶凉 提交于 2019-12-23 03:01:12

问题


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!


回答1:


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();


来源:https://stackoverflow.com/questions/8497073/in-linq-to-nhibernate-is-it-possible-to-use-fetch-after-a-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!