I am looking for the proper way to implent the following situation (using asp.net 2.0 and NHibernate 0.8.4.0):
Code:
class Foo
{ //some fields and properties
prviate IList myManyToManyCollection;
public IList MyManyToManyCollection
{
get{return myManyToManyCollection;}
}
...
}
I have no issues populating the collection via Nhibernate and everything seems to save and update properly.
My page maintains an IList that represents this many-to-many collection in Session[] from which the user can add or delete members from this IList using a web interface.
My desire is to replace the IList in my class with the IList maintained in session imediatly prior to the class being saved into the data base.
My current approach is the following:
Code:
protected void odsFoo_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
Foo f = e.InputParameters[0] as Foo;
//grab my updated list out of session
_myLocalIList = Session["myLocalList"] as IList;
//stick it into my class so it will get saved
f.MyManyToManyCollection = _myLocalIList;
}
(odsFoo is my object data source)
This causes the following error when Nhibernate calls
Code:
ISession session = orm.GetSession();
try
{
session.BeginTransaction();
----> session.SaveOrUpdate(obj);
session.Transaction.Commit();
}
"Illegal attempt to associate a collection with two open sessions "
As far as I can tell my sessions are closed, but I am realativly new to hibernate so I may have a gross misunderstanding of the process.
Any help or advice on tackling this issue would be appreciated.
[/code]