如何一次性设置 nHibernate ICriteria 的所有关联上的 Fetchmode?
我有一个与其他对象有很多关联的对象。所有这些都是由 nHibernate 延迟获取的,这在几乎所有情况下都很好。
在特定场景中,在本例中导出大量记录,我想将 Fetchmode 设置为渴望所有关联。有没有一种方法可以做到这一点,而不必手动指定每一个:
ICriteria crit = CreateCriteria().
.SetFetchMode("Address", FetchMode.Eager)
.SetFetchMode("ContactPerson", FetchMode.Eager);
我想找到的方法,但一直无法:
// This doesn't work.
ICriteria crit = CreateCriteria().SetFetchMode(FetchMode.Eager);
I have an object that has many assocations to other objects. All of these are fetched lazily by nHibernate, which is good in almost all cases.
In a particular scenario, in this case an export of a lot of records, I want to set the Fetchmode to eager on all associations. Is there a way to do this, without having to manually specify each one:
ICriteria crit = CreateCriteria().
.SetFetchMode("Address", FetchMode.Eager)
.SetFetchMode("ContactPerson", FetchMode.Eager);
The method I would like to find, but haven't been able to:
// This doesn't work.
ICriteria crit = CreateCriteria().SetFetchMode(FetchMode.Eager);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用 NHibernate 元数据。
我不确定这是否值得付出努力。
You could try to use the NHibernate Metadata.
I'm not sure if it is worth the effort.
不,没有办法以一揽子方式做到这一点。
No, there is no way to do this in a blanket fashion.