I think you'll run into threading issues if you leave the ISession in the HttpSession, even if you Reconnect() and Disconnect().
A couple of suggestions:
1) You can always hack around the lazy-load issue if you know ahead of time what parts you're going to need to load by accessing them at the time you first load the object.
Parent p = session.Get(typeof(Parent), parentID);
int throwaway = p.Children.Count; // force lazy-load of Children collection.
2) If you're not editing the object that is giving you the lazy-load issue in your multi-page transaction, you can just do a session.Refresh() on the object in question. This will reload its state from the DB and reassosciate it with the session.
3) If you're dealing with a bi-directional assosciation, you can work with the child objects alone and then just refresh the Parent object at the end.
i.e. instead of...
Parent p = session.Get(typeof(Parent), parentID);
// next request
p.AddChild(newChild); // this would give you the lazy-load exception
you do...
Parent p = session.Get(typof(Parent), parentID);
// next request
Child newChild = new Child();
newChild.Parent = p;
// do not add newChild to p.Children
// next request
session.Save(newChild);
session.Refresh(p); // p.Children now includes newChild
4) Look into ISession.SaveOrUpdateCopy(). I've never used it and I'm not sure precisely what it does, but it might have something to do with a solution to your problem.
OT: Are you from Ars?
|