问题
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