I have the logged user (Class: User) inside a Session variable.
The User has a collection of items of class Log (User.Logs) which is lazyly initialized.
I'm also using the Open-Session-In-View Pattern.
At some point, I use this code:
Code:
protected void ddlLogHistoryFilter_SelectedIndexChanged(object sender, EventArgs e)
{
User rUser = ((User)Session["LoggedUser"]);
theSession.Lock(rUser, None);
System.Collections.Generic.List<Log> logHistory = new System.Collections.Generic.List<Log>();
//some logic to filter and add the Logs from User.Logs to logHistory
gridViewLogHistory.DataSource = logHistory;
gridViewLogHistory.DataBind();
}
When I run this the first time, it works perfectly. But when I change the dropDownList selected item (thus firing the above procedure, it has AutoPostBack = true), when the debug gets to
gridViewLogHistory.DataBind();
NHibernate throws this error:
Could not initialize proxy - the owning Session was closed
I don't know why this is happening, my guess is User.Logs is cached somewhere thus the original session is closed, though I reattach User to the new session (with theSession.Lock) so if this is the case, I don't know why would this happen...
Can anyone help me?
Alejandro.