In a data-bound win-forms environment, I'm having NHibernate lazy load a collection.
When I disconnect the session, I get a LazyInitializationException - understandably.
So - To get round this problem, is it as simple as having AbstractPersistentCollection raise an event, before and after it initialises the colelction?
Code:
Fire BeforeLaztInitialise event here
if (session.IsConnected)
{
try
{
session.InitializeCollection(this, writing);
}
catch (Exception e)
{
log.Error("Failed to lazily initialize a collection", e);
throw new LazyInitializationException("Failed to lazily initialize a collection", e);
}
}
else
{
throw new LazyInitializationException("Failed to lazily initialize a collection - session is disconnected");
}
Fire AfterLazyInitialise event here.
This would allow the app to re-connect to the session, have NHibernate load the lazy collection, and then disconnect if necessary.
Or is there another way to do this ?
Thanks