我有一个模块,用于从拖动的对象中检索序列化的nhibernate对象:
DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
Object content = XamlServices.Load((new StringReader(dragObject.Xaml)));
但我在第二行得到一个例外:
failed to lazily initialize a collection, no session or session was closed
答案 0 :(得分:0)
我假设您的dragObject
是使用nhibernate序列化的对象。显然Xaml
属性是延迟加载的(或者访问类的延迟加载属性)。
您需要在访问所有延迟加载属性的同一会话中加载dragObject
:
using (ISession session = sessionFactory.OpenSession())
{
DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
Object content = XamlServices.Load((new StringReader(dragObject.Xaml)));
}
或者,您也可以急切加载延迟属性。