I need to save a hibernate object into session and then retrieve one of it's foreign key properties like this:
public ActionResult Login(LoginModel model, string returnUrl) {
User usr = _userRepository.GetById(Convert.ToInt32(ModelState["User"].Value.AttemptedValue));
Session["user"] = usr;
}
public ActionResult Index() {
Customer customerActive = Session["user"].Customer.Active;
// this line throws an error:
// Initializing[Myproj.Models.Customer#3]-Could not initialize proxy - no Session.
}
As User.Customer is a foreign key and NHIbernate lazy loads it, the call fails. How could I prevent this "No session" failure?