I run into an inconsistent behaviour of ILifecycle.OnLoad depending on the used fetch mode. I use OnLoad to register some events (PropertyChanged events) on the items of a collection after the parent is loaded.
Code:
void ILifecycle.OnLoad( ISession s, object id ) {
foreach ( T obj in Items )
obj.PropertyChanged += OnItemPropertyChanged;
}
When I use the default fetch mode it works fine (though the list gets initialized when I access the Items property in the loop). When I use FetchMode.Join, I get an LazyInitializationException in AbstractPersistentCollection.Initialize because the collection is in state "initializing" when I access "Items".
I know that my approach using OnLoad for that may be not the "cleanest" solution, but I couldn't figure out another way to guarantee that the events will be subscribe in every scenario (long story ...).
But I still wonder if when OnLoad is called the collections of the object shouldn't either be "uninitialized" (in case of lazy loading) or "initialized", but not "initializing".
Any thoughts on that ?
Thx for any help !