gpt4 book ai didi

.net - 使用 Ignore.NotFound 延迟加载 NHibernate

转载 作者:行者123 更新时间:2023-12-02 13:01:34 24 4
gpt4 key购买 nike

我有一个像下面这样的 Candidate 对象的映射:

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

这里的问题是,如果我选择 * Candidates 我会为每个人获得一个额外的选择,这不是一件好事,所以我取出了 NotFound().Ignore() 位,但现在以下代码失败并出现 ObjectNotFoundException 异常:

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

当我比较 County != null 时,有没有办法强制 Hhibernate 进行选择?

谢谢,

最佳答案

当您指定 .NotFound().Ignore() 时,这会强制急切加载实体并且无法使用 .LazyLoad() 覆盖。 NHibernate 这样做是因为它必须确保关系存在或不存在,因为您不依赖数据库来强制执行此操作。

我的建议是捕获 ObjectNotFoundException 或修复您的数据,这样就不会出现这些不一致的情况。

这是一篇关于此的文章:http://opensource.atlassian.com/projects/hibernate/browse/HHH-2753

关于.net - 使用 Ignore.NotFound 延迟加载 NHibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5663548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com