Exception "Illegal attempt to associate a collection with two open sessions" when saving object
- by Alex
I am using CastleProject ActiveRecord and I use lazy load feature of this ORM. In order to make lazy load work, it is required to create SessionScope. I do this in Program.cs:
public static SessionScope sessionScope;
private static void InitializeActiveRecord()
{
ActiveRecordStarter.Initialize();
sessionScope = new SessionScope();
}
This works fine for loading, however, when I try to save my objects, I get an exception saying "Illegal attempt to associate a collection with two open sessions". I guess this is due to the fact that I created one session myself.
How to avoid this exception?