The source field for the collection is null when using LinFu ProxyFactoryFactory in NHibernate

I have a problem when I try to switch from ProxyFactoryFactory Lock to LinFu ProxyFactoryFactory in NHibernate.

I have an object 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 maps to Fluent NHibernate as follows:

 public class FooDbMap : ClassMap<Foo> { public FooDbMap() { HasMany(x => x.Bars) .Access.CamelCaseField(Prefix.Underscore) .LazyLoad() .KeyColumn("FooId") .AsSet() .Cache.ReadWrite(); } } 

The ratio is bidirectional and is displayed as such on the side of the bar too.

The problem occurs when I call the AddBar method. The _bars collection is null and a NullReferenceException.

The problem disappears if I go back to the ProxyFactoryFactory castle.

The error does not occur with all associated collections, only one instance.

The problem still arises, even if I change _bars to read only! Therefore, someone manages to set the readonly field to null, even after the field has been assigned.

Any ideas?

+2
source share

Source: https://habr.com/ru/post/900908/


All Articles