我有对象层次结构 Parent->Child (延迟加载默认设置为 true) 现在我正在从数据库中加载所有 Parent 对象。所有子对象都将具有 ChildProxyGUID 类型。
然后我写
IList<Parent> parentList = NHibernateHelper.List<Parent>();
foreach(Parent parent in parentList)
{
if(!NHibernateUtil.IsInitialized(parent.Child))
{
NHibernateUtil.Initialize(parent.Child);
if(parent.Child.GetType() != typeof(Child)) //parent.Child.GetType() return me proxy type
throw new ArgumentException("wrong type");
}
}
如何将 parent.Child 转换为 Real 类型“Child”。由于系统检查,我需要真实类型(儿童)。这个例子在现实生活中很简单,我有一个非常复杂的映射和关系。
有什么想法吗?