c# - Entity Framework 简单名称会导致某些项目出现问题,但不会导致其他项目出现问题

标签 c# asp.net entity-framework azure-webjobs

我有一个 Visual Studio 2015 解决方案,其中包含大约 20 个项目。每个项目都引用 2 个使用 Entity Framework 6 的类库。在这些类库中,我们有相似的命名对象,它们驻留在不同的命名空间中。添加新的 Azure Web 作业项目后,我现在得到以下异常(仅针对 Web 作业项目):

An unhandled exception of type 'System.NotSupportedException' occurred in EntityFramework.dll

Additional information: The type 'AAA.BBB.Entity' and the type 'AAA.BBB.Entities.Entity' both have the same simple name of 'Entity' and so cannot be used in the same model. All types in a given model must have unique simple names. Use 'NotMappedAttribute' or call Ignore in the Code First fluent API to explicitly exclude a property or type from the model.

其他几个项目工作并且不会抛出此异常 - REST API、Websockets API、测试项目和标准网络应用程序。我比较了项目引用、属性、包等,但无法弄清楚有什么区别。我能看到的唯一区别是 Web 作业是一个控制台应用程序,其他的是 Web 应用程序和一个测试项目。

最佳答案

这是 EF 的已知限制 - https://entityframework.codeplex.com/workitem/483 .不幸的是,由于 EF6 的架构方式,修复起来极其困难。请注意,如果模型中只使用了一个冲突类,那么如果您使用 Code First 应该没问题——但如果您有 EDMX 模型,它将失败。尝试在同一模型中使用这两种类型总是会失败,无论您是使用代码优先还是 EDMX。

关于c# - Entity Framework 简单名称会导致某些项目出现问题,但不会导致其他项目出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33678562/

相关文章:

c# - 如何在 XmlNodeList 的 foreach 中使用反向?

c# - 在 C# 中使用 Uploadify

c# - 我如何在 Entity Framework 中执行此操作(多个 where's 或 Join)?

c# - 根据条件从列表中删除项目

c# - 如何将 Storyboard 用作样式

c# - 如何使用 EnumDropDownListFor 获得默认选定的枚举?

c# - 具有值匹配的 asp.net mvc 模型验证

c# - 制作面板及其所有控件的副本

c# - EF 核心的 hasRequired 的替代品是什么?

c# - 我可以安全地在文件夹上使用 `IO.File.GetAttributes` 吗?