FirstOrDefault() breaks FetchType=join with Linq to NHibernate

自作多情 提交于 2019-12-13 12:41:52

问题


If i do

Session.Linq<MyClass>().Where(x => x.Id = someId).FirstOrDefault();

where MyClass has a set of eager loaded child object on it, the FirstOrDefault() seems to prevent this from working by adding a TOP 1 to the SQL.

Is this just a bug (feature?) in Linq2NH (which i understand is being rewritten) or am I missing something?

Is there a preferred alternative which works properly?

Thanks


回答1:


Looks like a bug, in my opinion FirstOrDefault is a pretty well defined Linq operator and it has nothing to do with eager/lazy loading, so it should not break it.

I guess there are lots of such nuances, which cause that the library is not production ready. I suggest submitting the bug the the devs.

Falling back to DetachedCriteria (or HQL) in this case is the only option in my opinion.



来源:https://stackoverflow.com/questions/880061/firstordefault-breaks-fetchtype-join-with-linq-to-nhibernate

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