且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NHibernate:如何在一对一映射上启用延迟加载

更新时间:2022-04-03 07:44:14

除非强制性关联,否则不支持一对一的延迟加载.请参阅此处以了解原因.

Lazy loading of one-to-one isn't supported unless the association is mandatory. See here for the reasoning.

归结为以下事实:为了确定关系的另一端是否存在(N),Hibernate必须进入数据库.由于您已经对数据库进行了匹配,因此***加载整个对象.

It boils down to the fact that in order to decide if the other side of the relationship exists (N)Hibernate has to go to the database. Since you've already taken the database hit, you might as well load the full object.

在某些情况下,访问数据库只是为了查看相关对象是否存在而没有实际加载该对象是有道理的(如果相关对象非常沉重"),则NHibernate当前不支持该对象.

While there are cases where hitting the DB just to see if the related object exists without actually loading the object makes sense (if the related object is very "heavy"), it isn't currently supported in NHibernate.