开发者

Entity Framework - Already Defined

开发者 https://www.devze.com 2023-03-22 08:34 出处:网络
I have a problem with an EDMX file which I\'ve never encountered before. Seemingly randomly when the site is running or I\'m debugging, the EF will bomb out and complain that everything is re-defined.

I have a problem with an EDMX file which I've never encountered before. Seemingly randomly when the site is running or I'm debugging, the EF will bomb out and complain that everything is re-defined. I have to restart the app pool and re-attach the debugger every time, then start again from where I left off, after which it works again until the next time it bombs out.

I've already recreated the EDMX with a different name, hence MyAppEntities*1*

The error is:

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 def开发者_C百科ined. 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.


You may be changed the assembly name of the project that contained the model.

The reference to the original assembly was still in the client application.

ASP.net Web Application : - Manually delete dll and pdb files.

ASP.net Web Site: - Perform an IIS reset then flush out the asp.net temporary files in the folder C:\windows\microsoft.net\your framework version\temp asp.net files\


I had this same error. This is a problem about dlls, on my case was a duplicated dll.


For Those who's problem is not yet resolved, try modifying the connection String in web.config.

In My Case I changed connectionString

From

<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" />

To:

 <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" />

note that 'star' in metadata has been removed, so that meta data is pointed to absolute location. Because of 'star' EF is searching everywhere. Hence duplicates might be encountered

Note: This is a simple fix, which means you are not clearing any duplicate data, which is not a good idea. The best way is to delete duplicate .pdb/.dll files as suggested by previous answers.


I had the same problem with a diferent solution, i have a two projects using entity framework, with models of the same database with the same name, all the tables that had added on both models where on the inner exception message, the solution was to rename one of the models


I have hit this problem whilst working on a process to allow assemblies for sub-applications to be loaded dynamically without requiring the whole app to be restarted. I am using EF 5.0 with DbContext. My workaround was to:

  1. Change the Entity Container Name so the it reflects the assembly version, e.g. CustomerEntities_1_0_7_0 and save the edmx.
  2. Manually amend the context to remove the version suffix:

    public partial class CustomersEntities : DbContext
    {
    public CustomersEntities() : base("name=CustomersEntities")
    
  3. Manually amend app.config likewise.


I just had that same problem. Entity Framework generated files CANNOT be in App_Code folder. I mean EDMX files.

I bet you had error that you wasn't able to reference files, so you checked property from Content to Compile. That solved VS error, but created double instances - precompiled one and runtime compiled.

Solution is to keep it away from App_code folder as it is special folder for code only.


For my case, deleting the model and creating it with new name solved this issue


I faced this exception recently and the solution to this problem is to delete an old DLL or duplicate DLL referenced in your solution Bin folder. This completely solved my problem.


After digging for 2 days finally I found the cause of the problem. I had 2 dll's (database application) which pointing to same entity framework database in the same project. In short it had duplicate dll's for one database. After removing irrelevant dll, it started working fine.


Clean, rebuild, deploy in release mode.


I finally solve my own problem and it was really nonsense. I just exclude (Exclude from project) folder which contain Model.edmx files

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号