无与伦比的参考NHibernate的防止延迟加载 [英] NHibernate Prevent Lazy Loading of unmatched reference

查看:218
本文介绍了无与伦比的参考NHibernate的防止延迟加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有NHibernate的相当有问题。我从表1至表2的参考,我想NHibernate的到,当一个相应的记录中没有发现表2,不要再发出对表2中的SELECT语句,来,我不知道,让真的确信它实际上是不存在的。

I have quite a problem with NHibernate. I have a reference from Table1 to Table2, and I want NHibernate to, when a corresponding record is not found in Table2, to not then issue a SELECT statement against Table2, to, I don't know, make really really sure that it actually isn't there.

我已经尝试添加像 .LazyLoad(Laziness.False)改性剂 .NotFound.Ignore()我的参考,但NHibernate的快活地忽略我的命令极端的偏见,发行其选择,打破我的代码。

I've tried adding modifiers like .LazyLoad(Laziness.False) and .NotFound.Ignore() to my reference, but NHibernate gaily ignores my commands with extreme prejudice, issuing its select and breaking my code.

迫切需要帮助,从负责这一滑稽的人或者一个很好的解释。

Urgent help needed, alternatively a good explanation from the person responsible for this travesty.

推荐答案

这是正确的,即NHiberante尝试加载不exsiting。他的必须做到这一点。

It is correct, that NHiberante tries to load "not exsiting". He must do that.

由于这里所说的 Ayende - NHibernate的映射(摘录):

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

12)未找到另一个遗产的功能,它控制NHibernate的
当它发现一个无效的外键的行为方式。即,
点至不存在的实体的值。默认情况下,这将引发
错误,因为这通常表明与数据库的问题,而是
与传统的数据库,你可以告诉它来设置属性值
null替代。

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.

和作为可以在这里找到:懒惰装载了NHibernate的与Ignore.NotFound (摘录):

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

在指定.NotFound()忽略()这迫使实体为
急切装载,并且不能与.LazyLoad被覆盖()。
NHibernate的这样做,因为它必须确保关系
存在或不存在的,因为你不依赖数据库
上强制执行此。

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.

和这里为什么NHibernate的赢T延迟加载我多到一的关系,何塞F. Romaniello说:

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

这是你的问题, NHibernate的必须予以肯定,认为发票
存在或不为每个招生存在。

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

标识强烈建议您解决您的数据问题,并删除
未找到=忽略属性。这是一件坏事。

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

这篇关于无与伦比的参考NHibernate的防止延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆