实体框架 - 已定义

时间:2011-07-24 15:24:43

标签: c# .net entity-framework entity-framework-4 edmx

我遇到过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.

10 个答案:

答案 0 :(得分:53)

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

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

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

ASP.net网站:   - 执行IIS重置,然后刷新asp.net临时文件    文件夹C:\ windows \ microsoft.net \您的框架版本\ temp    asp.net文件\

答案 1 :(得分:4)

我有同样的错误。这是一个关于dll的问题,在我的案例中是一个重复的dll。

答案 2 :(得分: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文件,如前面的答案所示。

答案 3 :(得分:3)

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

答案 4 :(得分:2)

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

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

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

答案 5 :(得分:2)

我刚遇到同样的问题。实体框架生成的文件 CAN NOT 位于App_Code文件夹中。我的意思是EDMX文件。

我敢打赌你有错误,你无法引用文件,所以你检查了属性从内容到编译。这解决了VS错误,但创建了双实例 - 预编译的一个和运行时编译。

解决方案是远离App_code文件夹,因为它只是代码的特殊文件夹。

答案 6 :(得分:2)

对于我的情况,删除模型并使用新名称创建它解决了这个问题

答案 7 :(得分:0)

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

答案 8 :(得分:0)

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

答案 9 :(得分:-1)

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