开发者

Lazy loading for NHibernate with Ignore.NotFound

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

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

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.Coun开发者_如何学Gotry != null)
{
       bos.CountryName = entity.Country.Name;
}

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

Thank you,


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.

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜