NHibernate Prevent Lazy Loading of unmatched reference

耗尽温柔 提交于 2019-12-02 04:56:52
Radim Köhler

It is correct, that NHibernate tries to load "not existing". It must do that.

As stated here Ayende - NHibernate Mapping (an extract):

12) not-found is another legacy feature, it controls how NHibernate behaves when it finds an invalid foreign key. That is, a value that points to an entity that doesn’t exist. By default, this would trigger an error, as this generally indicate a problem with the database, but with legacy database, you can tell it to set the property value to null instead.

And as could be found here: Lazy loading for NHibernate with Ignore.NotFound (an extract):

When you specify the .NotFound().Ignore() this forces the entity to be eagerly loaded and cannot be overriden with the .LazyLoad(). NHibernate does this because it has to be sure that relationship exists or doesn't exist since you are not relying on the database to enforce this.

And here Why Nhibernate won't lazy load my many-to-one relationship?, José F. Romaniello says:

This is your problem, nhibernate must to be sure, that an invoice EXIST or do not exist for each enrollment.

I'd strongly recommend you to fix your data problems and remove the not-found="ignore" attribute. It is a bad thing.

try

.Not.LazyLoad(); 

instead of .LazyLoad(laziness.false);

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