例:
public class ParentObj
{
public virtual int Id { get; set; }
public virtual IList<ChildObj> ChildCollection { get; set; } //Lazy loaded
}
1 ページ (web) で親オブジェクトを取得するいくつかのメソッド
ParentObj parentObj;
using (var session = GetSesion())
using (var tx = session.BeginTransaction())
{
parentObj = session.Get<ParentObj>(1);
//Don't want to call NHibernateUtil.Initialize() here
//because ChildCollection is not needed for the current operation
}
parentObj を別のページに転送し、次に ChildCollection にアクセスする必要があります
var parentOjb = GetParentOjbFromPreviousPage();
using (var session = GetSesion())
using (var tx = session.BeginTransaction())
{
parentOjb = session.Merge(parentObj);
NHibernateUtil.Initialize(parentObj.ChildCollection); //exception thrown here
}
エラー メッセージ: コレクションはどのセッションにも関連付けられていません
私は何を間違っていますか?このシナリオで ChildCollection を初期化する唯一の方法は、Get() を再度呼び出すことですか?