I want to store my object in ASP.NET Session. This object has some lazy loaded properties. When I do postback to my page and get my object from Session, this properties throw LazyInitializationException. Can I rebind this object to newly creates Nhibernate Session to retrieve this properties or I have to create Session and get this object on each request?
1 Answer
You need to eagerly fetch those objects at the moment you send the SQL query so that they are populated and accessible from the session on the next request. Once the session that was used to retrieve the parent object is closed you cannot fetch them anymore.
3 Comments
Tror
I dont want feth them eagerly, beacuse they are quite large. So, as I understand, I need to fetch this object on each request. Thanks
Darin Dimitrov
But if you are going to store it into the ASP.NET session why would you fetch it on each request? Why not fetch the whole object once and then cache it?
Tror
Maybe I do something wrong? but some objects may contain more than 10000 child objects.