tags:

views:

48

answers:

1

Dear All,

I have a Nhibernate Class Library, And Web App references it, I get data form Product table, It's fine, but when i refresh it, I occur this issue.

Please see image below:

http://vi-vn.com/pubs/images/NhibernateWeb.jpg

Thanks, NeonQuach

+1  A: 

The error message images you have linked indicate to me that you are probably attempting to access a session after it has already been closed. This commonly occurs when trying to access lazy-loaded collections/references. For example:

class MyObject
{
    public virtual IList<MyOtherObject> MyObjects { get; set; }
}

MyObject obj = session.Load<MyObject>(1);

// Some stuff happens, the session is explicitly closed or goes out of scope

// Later, obj is still tied to the (now closed) session but code tries to:
int count = obj.MyObjects.Count; // MyObjects is lazy-loaded, NHibernate tries to query

NHibernate sees that the MyObjects collection is lazy-loaded and has not been initialized yet, so it tries to query for the collection via the session that it is associated with. However, that session is already closed so it throws an ObjectDisposedException and says "Session is closed!"

The solution is to either pre-load your collection or make sure the session does not go out of scope or is explicitly disposed before you are done with it.

Stuart Childs
@Stuart Childs + All: thank you I solved my isuee
nguyen