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

标签 .net nhibernate fluent-nhibernate

我有一个像下面这样的 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/

相关文章:

c# - 从 ObservableCollection 中删除空项

c# - String.Empty 或 null : what is better to return for "Error" field from service?

nhibernate - NHibernate FetchMany 在两个以上的表上是否损坏?

sql - 单个列的多个外键

nhibernate - 在不创建额外列的情况下映射外键以及 NHibernate 中的引用

.net - Stopwatch.GetTimestamp() 替代方案在多个处理器上是安全的

.net - 我可以从该字典的枚举循环中删除 ConcurrentDictionary 中的项目吗?

c# - NHibernate vs Entity Framework 6 对大量用户的性能

.net - 将外键映射到主键以外的东西

nhibernate - Fluent NHibernate 自动映射 : One-to-many entities, 多对多后端?