FluentNHibernate:LazyLoad和Fetch [英] FluentNHibernate: LazyLoad and Fetch

查看:232
本文介绍了FluentNHibernate:LazyLoad和Fetch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在流利的nhibernate中,我可以将Fetch.Something和Not.LazyLoad设置为Reference或HasMany。如果我同时使用这两种方法会发生什么?



这两种方式如何反映以这三种方式查询数据?

  class UserMap 
{
HasMany(x => x.Contacts)。 (Fetch或Not.LazyLoad)
References(x => x.Supervisor)。 (Fetch or Not.LazyLoad)
}

session.Query< User>();
session.Query< User>()。FetchMany(x => x.Contacts);
session.Get< User>(ID);


解决方案

问题在于 Query / HQL不考虑。因此,在运行查询之后,它会立即尝试获取 Not.LazyLoad 属性一个



一般来说,在99%的情况下禁用延迟加载是一个坏主意。建议阅读: NHibernate是懒惰的,只是住它a>


in fluent nhibernate I can set Fetch.Something and Not.LazyLoad to a Reference or HasMany. What will happen if I use both?

How these two reflects to querying data in these three ways?

class UserMap
{
   HasMany(x=>x.Contacts). (Fetch or Not.LazyLoad)
   References(x=>x.Supervisor). (Fetch or Not.LazyLoad)
}

session.Query<User>();
session.Query<User>().FetchMany(x=>x.Contacts);
session.Get<User>(ID);

解决方案

The problem is that Fetch is not taken into account for Query/HQL. So, immediately after running the query, it will try to fetch your Not.LazyLoad properties one by one.

In general, disabling lazy loading is a bad idea in 99% of the cases. Suggested read: NHibernate is lazy, just live with it

这篇关于FluentNHibernate:LazyLoad和Fetch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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