FluentNHibernate: LazyLoad and Fetch

故事扮演 提交于 2019-12-11 09:47:46

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/10717845/fluentnhibernate-lazyload-and-fetch

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