FirstOrDefault()打破FetchType = join与Linq到NHibernate [英] FirstOrDefault() breaks FetchType=join with Linq to NHibernate

查看:382
本文介绍了FirstOrDefault()打破FetchType = join与Linq到NHibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我愿意

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

其中,MyClass上有一组渴望加载的子对象,而FirstOrDefault()似乎通过在SQL中添加TOP 1来阻止此子对象的工作.

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.

这仅仅是Linq2NH中的错误(功能?)(据我所知正在被重写)还是缺少某些东西?

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?

谢谢

推荐答案

在我看来,FirstOrDefault是一个定义良好的Linq运算符,与渴望/延迟加载无关,它看起来像个错误.它.

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.

在我看来,这种情况下退回到DetachedCriteria(或HQL)是唯一的选择.

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

这篇关于FirstOrDefault()打破FetchType = join与Linq到NHibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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