是否可以在 Code First 中设置具有不同 DbContext 的 FK?

Is it possible to set a FK with different DbContext in Code First?

我一直试图在 Entity Framework Code First 中将我的数据库实体拆分为多个 DbContext。但是,我需要为在不同 DbContext 中定义的两个表设置一对多关系。 当我尝试执行 enable-migrations 命令时出现以下错误:

有什么办法可以处理这种情况还是entity framework中的限制?

请注意,错误消息中包含的 TestTable 不是 SKContext 的成员。它属于另一个 DbContext。

解决方法是: modelBuilder.Ignore(); 正如法比奥卢兹所说。 感谢他

尽量避免使用modelBuilder.Ignore<TestTable>();

创建TestTable