gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 23:26:23 24 4
gpt4 key购买 nike

我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com