延迟加载NHibernate的与Ignore.NotFound [英] Lazy loading for NHibernate with Ignore.NotFound

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

问题描述

我有这样的波纹管的候选对象的映射:

I have a mapping like the bellow for a Candidate object:

References(x => x.Country).Column("CountryId").NotFound().Ignore()

这里的问题是,如果我选择*考生,我得到一个额外的选择为他们每个人的,不是一件好事,所以我拉出NOTFOUND()。忽略()位,但现在下code失败与ObjectNotFoundException异常:

the problem here is, if I select * Candidates I get a extra select for each of them, not a good thing, so I pull out the NotFound().Ignore() bit but now the following code fails with ObjectNotFoundException exception:

if (entity.Country != null)
{
       bos.CountryName = entity.Country.Name;
}

有没有办法强制Hhibernate做选择时,我比较县!= NULL?

Is there a way to force Hhibernate do the select when I compare County != null ?

感谢您,

推荐答案

在指定.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.

我的建议是要么赶ObjectNotFoundException或修复您的数据,你没有这些不一致的地方。

My suggestion would be to either catch the ObjectNotFoundException or to fix your data such that you don't have these inconsistencies.

下面是关于这方面的文章: http://opensource.atlassian.com/项目/休眠/浏览/ HHH-2753

Here's an article about this: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2753

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

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