32

我以前从未遇到过的 EDMX 文件有问题。当站点正在运行或我正在调试时,似乎是随机的,EF 会爆炸并抱怨一切都被重新定义了。我每次都必须重新启动应用程序池并重新附加调试器,然后从我离开的地方重新开始,之后它会再次工作,直到下一次它爆炸。

我已经用不同的名称重新创建了 EDMX,因此 MyAppEntities* 1 *

错误是:

Error: Schema specified is not valid. Errors: App_Code.Fck.csdl(3,4) : 
error 0019: The EntityContainer name must be unique. An EntityContainer with the name 'MyAppEntities1' is already defined. App_Code.Fck.csdl(69,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.AdSection' was already defined. App_Code.Fck.csdl(79,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.AgeRating' was already defined. App_Code.Fck.csdl(89,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Comment' was already defined. App_Code.Fck.csdl(101,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.ContentImage' was already defined. App_Code.Fck.csdl(115,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.ContentVideo' was already defined. App_Code.Fck.csdl(126,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FeaturePlan' was already defined. App_Code.Fck.csdl(142,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Flick' was already defined. App_Code.Fck.csdl(165,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Gallery' was already defined. App_Code.Fck.csdl(184,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Genre' was already defined. App_Code.Fck.csdl(197,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Like' was already defined. App_Code.Fck.csdl(208,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Meta' was already defined. App_Code.Fck.csdl(216,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.Payment' was already defined. App_Code.Fck.csdl(236,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.StatusUpdate' was already defined. App_Code.Fck.csdl(246,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.UserProfile' was already defined. App_Code.Fck.csdl(277,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_FeaturePlans_AdSections' was already defined. App_Code.Fck.csdl(289,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Flicks_AgeRatings' was already defined. App_Code.Fck.csdl(301,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Comments_Users' was already defined. App_Code.Fck.csdl(313,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Payments_FeaturePlans' was already defined. App_Code.Fck.csdl(325,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Flicks_Users' was already defined. App_Code.Fck.csdl(337,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Genres_Genres' was already defined. App_Code.Fck.csdl(349,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Likes_Users' was already defined. App_Code.Fck.csdl(361,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Payments_Users' was already defined. App_Code.Fck.csdl(373,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_StatusUpdates_Users' was already defined. App_Code.Fck.csdl(385,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FlickGenres' was already defined. App_Code.Fck.csdl(389,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.User' was already defined. App_Code.Fck.csdl(401,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_Users_be_Users' was already defined. App_Code.Fck.csdl(413,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.ContentImageSet' was already defined. App_Code.Fck.csdl(426,4) : 
error 0019: Each type name in a schema must be unique. Type name 'FckModel.FK_ContentImages_ContentImageSets' was already defined.
4

10 回答 10

56

您可能会更改包含该模型的项目的程序集名称。

对原始程序集的引用仍在客户端应用程序中。

ASP.net Web 应用程序: - 手动删除 dll 和 pdb 文件。

ASP.net 网站: - 执行 IIS 重置,然后清除文件夹 C:\windows\microsoft.net\your framework version\temp asp.net files\ 中的 asp.net 临时文件

于 2011-07-24T16:26:04.407 回答
4

我有同样的错误。这是关于 dll 的问题,在我的情况下是重复的 dll。

于 2013-01-15T10:55:28.977 回答
4

对于那些问题还没有解决的,尝试修改web.config中的连接字符串。

在我的情况下,我更改了 connectionString

<add name="StudentRegistrationDB" connectionString="metadata=res://*/App_Code.EFDataModel.StudentReg.csdl|res://*/App_Code.EFDataModel.StudentReg.ssdl|res://*/App_Code.EFDataModel.StudentReg.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=StudentRegistration;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

至:

 <add name="StudentRegistrationDB" connectionString="metadata=res://App_Code.EFDataModel2.StudentRegDB.csdl|res://App_Code.EFDataModel2.StudentRegDB.ssdl|res://App_Code.EFDataModel2.StudentRegDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=StudentRegistration;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

请注意,元数据中的“星号”已被删除,因此元数据指向绝对位置。因为'明星' EF 到处搜索。因此可能会遇到重复

注意:这是一个简单的修复,这意味着您不会清除任何重复数据,这不是一个好主意。最好的方法是按照先前答案的建议删除重复的 .pdb/.dll 文件。

于 2016-12-04T13:28:07.940 回答
3

我在使用不同的解决方案时遇到了同样的问题,我有两个项目使用实体框架,具有相同名称的相同数据库的模型,在两个模型上添加的所有表在内部异常消息上,解决方案是重命名其中一个模型

于 2015-01-20T05:05:10.497 回答
2

我在处理允许动态加载子应用程序的程序集而不需要重新启动整个应用程序的过程时遇到了这个问题。我正在使用带有 DbContext 的 EF 5.0。我的解决方法是:

  1. 更改实体容器名称,使其反映程序集版本,例如 CustomerEntities_1_0_7_0 并保存 edmx。
  2. 手动修改上下文以删除版本后缀:

    public partial class CustomersEntities : DbContext
    {
    public CustomersEntities() : base("name=CustomersEntities")
    
  3. 同样手动修改 app.config。

于 2013-04-05T08:43:31.327 回答
2

我只是有同样的问题。实体框架生成的文件不能位于 App_Code 文件夹中。我的意思是 EDMX 文件。

我敢打赌,您遇到了无法引用文件的错误,因此您检查了从 Content 到 Compile 的属性。这解决了 VS 错误,但创建了双实例 - 预编译一个和运行时编译。

解决方案是将其远离 App_code 文件夹,因为它是仅用于代码的特殊文件夹。

于 2013-12-18T20:29:17.397 回答
2

就我而言,删除模型并使用新名称创建它解决了这个问题

于 2015-09-28T07:23:08.430 回答
1

我最近遇到了这个异常,这个问题的解决方案是删除一个旧的 DLL 或在您的解决方案 Bin 文件夹中引用的重复 DLL。这完全解决了我的问题。

于 2020-01-02T10:42:45.657 回答
0

经过两天的挖掘,我终于找到了问题的原因。我有 2 个 dll(数据库应用程序)指向同一个项目中的同一个实体框架数据库。简而言之,它有一个数据库的重复 dll。删除无关的dll后,它开始正常工作。

于 2018-01-23T13:32:42.630 回答
-1

在发布模式下清理、重建、部署。

于 2016-11-18T06:41:44.510 回答