在Entity Framework中将大型模型划分为较小的模型

时间:2014-01-21 15:56:33

标签: c# entity-framework entity-framework-6

如何有效地将一个非常大的模型(800个实体)划分为几个较小的模型?

我将现有数据库反向设计为Entity Framework实体。我已经将我的模型划分为15个较小的模型 - 每个模型都有自己的DbContext类。问题是一些实体共享模型之间的关系,所以我最终得到许多“EntityType'foo'没有定义键。定义此EntityType的键”错误。对于这些,我继续调用modelBuilder.Ignore()来防止抛出此错误。然后我开始得到一个不同的错误:

System.InvalidOperationException: The navigation property 'Bar' is not a declared 
property on type 'Foo'. Verify that it has not been explicitly excluded from 
the model and that it is a valid navigation property.

但是在Foo中定义了一个名为Bar(带有Bar类型)的虚拟属性。所以我确信这是调用Ignore()的直接结果。

这样做的正确方法是什么?

0 个答案:

没有答案