0

I'm receiving on my controller some int which is parameter I'm using for getting entity. This entity have List Collection which I need to load together with my entity. I cannot access Fetch method in session.Get so I dont know how to achive. When in my view I tried to access to my collection like entity.Collection it throws an error, no session or session was closed

Here is my code

public ActionResult Details(int id)
{
   MyDomain.Property data = null;
   using (//open session)
   {
      using (//using transaction)
      {
          data = session.Get<MyDomain.Property>(id);                    
          //I need to load Photo() collection. 
          transaction.Commit();
      }
   }
   return PartialView("DetailsPartial", data);        
}

1 Answer 1

1

Your entity has a collection's property with a proxy (not real collection). When you close session you can't use lazy load, so, you need to get real collection objects. You should get it with query:

Session.QueryOver<Entity>()
 .Where(entity => entity.Id == id)
 .Fetch(entity => entity.CollectionProperty).Eager
.SingleOrDefault<Entity>();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.