0
개체 계층 구조 부모 -> 자식이 있습니다. (지연 로딩은 기본적으로 true로 설정됩니다.) 이제 데이터베이스에서 모든 부모 개체를로드하고 있습니다. 모든 자식 객체의 유형은 ChildProxyGUID입니다. NHibernate.Initialize (proxyObject)를 호출 한 후 objectType이 잘못되었습니다.
는 내가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을 변환 할 수 있습니다 쓰기. 시스템 검사 때문에 실제 유형 (하위)이 필요합니다. 이 예제는 실생활에서 단순합니다. 매우 복잡한 매핑과 관계가 있습니다.
아이디어가 있습니까?
var realObject = session.GetSessionImplementation()
.PersistenceContext.Unproxy(parent.Child)
그러나, 그것은 유지하기 어렵 코드를 창조하는 LSP을 위반으로 코드가, 검사의 유형에 의존해야하는 나쁜 생각 :
LSP에 관해 절대적으로 동의합니다. 그래서 코어에서 몇 가지 변경을했는데 이제는 Proxy 클래스로 작업하고 있습니다. 감사 – Step