2012-03-19 2 views
0

내 컨트롤러에서 엔티티를 가져 오는 데 사용하는 매개 변수 인 int를 수신 중입니다. 이 엔티티에는 엔티티와 함께로드해야하는 List Collection이 있습니다. session.Get에서 Fetch 메소드에 액세스 할 수 없으므로 어떻게 작성해야하는지 잘 모릅니다. 내보기에 나는 그것이 어떤 세션이나 세션이 종료되지 않은 오류를 발생 entity.Collection처럼 내 컬렉션에 액세스하려고하면 다음세션에서 Nhibernate 지연로드 오류가 발생했습니다. 가져 오기

내 코드입니다

귀하의 실체는 콜렉션의 속성이
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

프록시 (실제 컬렉션 아님). 세션을 닫을 때 게으른로드를 사용할 수 없으므로 실제 콜렉션 객체를 가져와야합니다. 검색어와 함께 표시됩니다.

Session.QueryOver<Entity>() 
.Where(entity => entity.Id == id) 
.Fetch(entity => entity.CollectionProperty).Eager 
.SingleOrDefault<Entity>(); 
관련 문제