Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework - Already 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 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.
like image 269
Echilon Avatar asked Jul 24 '11 15:07

Echilon


7 Answers

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\

like image 169
Damith Avatar answered Oct 30 '22 21:10

Damith


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

like image 39
Lücks Avatar answered Oct 30 '22 23:10

Lücks


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.

like image 4
Ganesh Vellanki Avatar answered Oct 30 '22 23:10

Ganesh Vellanki


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

like image 3
Rafael Avatar answered Oct 30 '22 22:10

Rafael


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.

like image 2
johndsamuels Avatar answered Oct 30 '22 21:10

johndsamuels


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.

like image 2
Gumowy Kaczak Avatar answered Oct 30 '22 21:10

Gumowy Kaczak


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

like image 2
Yasser Amer Avatar answered Oct 30 '22 21:10

Yasser Amer