English 中文(简体)
精液:懒惰和挑取
原标题:FluentNHibernate: LazyLoad and Fetch

在流利的弹簧中我可以设置 Fetch 。 有些东西还是没有。 Lazy Load to a reference 或 HasMany。 如果我同时使用, 会发生什么?

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

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);
最佳回答

问题是查询/ HQL 不考虑 < code> Fetch 。 所以, 在运行查询后, 它会立即尝试将您的 < code> 不。 Lazy Looad 属性 < strong > 以 < / strong > 方式获取 。

总的来说,在99%的个案中,拆卸懒惰装载是一个坏主意。建议如下:Nhebertate是懒惰的,只管与它一起生活

问题回答

暂无回答




相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

热门标签