2014-09-28 81 views
1

以下代碼嘗試檢索作爲斷開連接圖的導航屬性的對象。測試以查看導航屬性是否可以檢索值

如果屬性未加載發生錯誤時

的ObjectContext的實例已設置,並且不能再用於需要連接

操作 是否有辦法我可以測試該屬性是否加載?

navProps = GetNavigationProperties(originalEntity); 
foreach (PropertyInfo navProp in navProps) 
{ 
    object obj = navProp.GetValue(item); // fails if the property type is an unloaded collection 
    // more code 
} 

回答

0

this question的回答對我有幫助。 我發現,如果我包括

Configuration.ProxyCreationEnabled = false; 
在構造

到我的上下文,然後navProp.GetValue(項目)返回null,而不是引發錯誤

相關問題