我在问题
我绕着这里工作 通过循环我的收藏 我的收藏 包含混合的 兄弟姐妹类型, 单个调用
ctx.Entry(myDerivedType).Reference("PropOfDerivedType").Load();
这导致许多额外的往返访问数据库,但至少是起作用了。
现在我需要装入这样的对象等级, 并将其保存在 MVC 网络应用程序的会话中。 由于 < code> DbContext code > 不应该是会话的一部分, 因此我 < em> 相信 em >, 我必须装入对象图 < code> AsNoTracking () code >, 比如 :
var myGraph = (from my in ctx.MyHierarchyRoot.Include("NonDerivedStuff")
.AsNoTracking()
where CONDITION select my).Single();
<强度问题1 强度>
如果对象图形要存储在会话中, 是否有必要使用 < code>. AsNoTrading () ?
然后我再通过从中得来的兄弟姊妹 在等级制度里转身, 并试图装载他们像这样:
foreach (SomeBase b in myGraph.SomeCollection)
{
if (b is SomeConcreteDerivedType)
{
ctx.Entry(b).Reference("SomePropertyOfSomeConcreteDerivedType").Load();
}
}
然而,由于我用.AsNoTracking
()装载我的格子,我明白了:
Member Load cannot be called for property SomePropertyOfSomeConcreteDerivedType because the entity of type SomeConcreteDerivedType does not exist in the context. To add an entity to the context call the Add or Attach method of DbSet.
<强问题2 强>
假设问题1的答案是“是”,我如何正确装载衍生物类型的导航特性?