在 NHibernate 中使用 LinFu ProxyFactoryFactory 时,集合的支持字段为 null
当我尝试从 NHibernate 中的 Castle ProxyFactoryFactory 切换到 LinFu ProxyFactoryFactory 时遇到问题。
我有一个像这样的实体:
public class Foo
{
private ISet<Bar> _bars = new HashedSet<Bar>();
public virtual void AddBar(Bar bar)
{
if (!_bars.Contains(bar)
_bars.Add(bar);
bar.Foo = this;
}
}
这是用 Fluent NHibernate 映射的,如下所示:
public class FooDbMap : ClassMap<Foo>
{
public FooDbMap()
{
HasMany(x => x.Bars)
.Access.CamelCaseField(Prefix.Underscore)
.LazyLoad()
.KeyColumn("FooId")
.AsSet()
.Cache.ReadWrite();
}
}
关系是双向的,并且在 Bar 侧也如此映射。
当我调用 AddBar 方法时出现问题。 _bars 集合为 null,并抛出 NullReferenceException。
如果我切换回 Castle ProxyFactoryFactory,问题就会消失。
并非所有映射集合都会发生该错误,仅此一个实例会发生该错误。
即使我将 _bars 更改为只读,问题仍然出现!因此,有人设法将只读字段设置回 null,即使在分配该字段之后也是如此。
有什么想法吗?
I am having a problem when I try switching from the Castle ProxyFactoryFactory to the LinFu ProxyFactoryFactory in NHibernate.
I have an entity like this:
public class Foo
{
private ISet<Bar> _bars = new HashedSet<Bar>();
public virtual void AddBar(Bar bar)
{
if (!_bars.Contains(bar)
_bars.Add(bar);
bar.Foo = this;
}
}
This is mapped with Fluent NHibernate like this:
public class FooDbMap : ClassMap<Foo>
{
public FooDbMap()
{
HasMany(x => x.Bars)
.Access.CamelCaseField(Prefix.Underscore)
.LazyLoad()
.KeyColumn("FooId")
.AsSet()
.Cache.ReadWrite();
}
}
The relationship is bi-directional and is mapped as such on the Bar side too.
The problem occurs when I call the AddBar method. The _bars collection is null, and a NullReferenceException is thrown.
The problem goes away if I switch back to the Castle ProxyFactoryFactory.
The error doesn't occur with all mapped collections, just this one instance.
The problem still occurs even if I change _bars to readonly! So someone is managing to set a readonly field back to null, even after the field has been assigned.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论