[ACCEPTED]-The EntityContainer name must be unique. An EntityContainer with the name 'Entities' is already defined-exception-handling

Accepted answer
Score: 166

Hijacking this, since it is the top Google 8 result for the error message.

In case anyone 7 else encounters this while only using a 6 single model/context: I once ran into this 5 problem because the assembly containing 4 the model/context was renamed and a copy 3 with the previous name remained in the 2 bin directory of the application. The solution 1 was to delete the old assembly file.

Score: 50

Your two EDMX files probably have the same 6 entity container name. You need to change 5 (at least) one of them.

In the GUI designer, open 4 Model Browser. Look for a node that says 3 "EntityContainer: Entities". Click it. In 2 Properties, change Name to something else. Save 1 and rebuild.

Score: 21

I had the problem too but my solution was 4 to clean the bin directory and then remove 3 the connection string with the entity container 2 name. Then I could rename my entities and 1 put back the connection string.

Score: 5

I renamed my project but the old file was 2 still in the bin folder. I just had to delete 1 the old DLL from the bin folder.

Score: 3

I have found a way to save multiple containers 29 with the same name (namespaced of course).

In 28 EF5 and VS2012 you can set three different 27 namespaces. First you can click on the edmx 26 file in the solution browser and in the 25 properties windows you can set the "Custom 24 Tool Namespace", you can click on the *.Context.tt 23 file right below the edmx and set another 22 namespace there, and finally thanks to a 21 lead from Mr Stuntz awesome answer I realized 20 that by opening the edmx file and clicking 19 in the white space you get another namespace 18 field under Schema in the properties window.

Think 17 we're done, not quite, I know you can see 16 the Entity Container Name field and will 15 try to change the name there but that doesn't 14 seem to work, you get a little error that 13 pops up. Ensure that all your edmx files 12 have an individual namespace there. (I ensured 11 I had a unique namespace in all three places)

Then 10 go to your Model Browser and right click 9 on EntityContainer: Entity to go to properties 8 and change the name of your container(s). From 7 that window with the namespace set everywhere 6 I was able to get multiple contexts with 5 the same name. I was dealing with things 4 like blahcontext and blahcontextcontainer 3 all of a sudden even though they were in 2 different folders.

When you see that its 1 a namespace problem. Or lack thereof.

Score: 3

In my case, the problem was caused by my 6 connection string in Web.config being named 5 the same thing as my entities container 4 class.


<add name="ConflictingNameEntities" connectionString="metadata=res://*/blahblah


<add name="ConflictingNameEntitiesConnection" connectionString="metadata=res://*/blahblah

and regenerate the container 3 class by right-clicking ConflictingNameModel.Context.tt 2 in Solution Explorer and clicking "Run Custom 1 Tool".

Score: 1

I just ran into this. It looks like somehow 21 Entity Framework got into a bad state in 20 terms of what tables it thought it needed 19 to add.

Normally EF will not recognize that 18 a new table has to be created until you 17 put the line

public virtual DbSet<NewTable> NewTable { get; set; }

inside your context class.

However, EF 16 somehow got into a bad state where the mere 15 presence of the NewTable class in my solution 14 was triggering it to think that it needed 13 to generate that table. So by the time the 12 above line in the context triggered it to 11 create a NewTable table, it already thought 10 it had done it, hence the error about duplicate 9 entities.

I just removed the NewTable class 8 from my solution, commented things out so 7 it would compile again (thankfully there 6 wasn't too much of this), then added a new 5 migration to make sure it was blank as it 4 should have been. Then once things were 3 back into a more predictable state, I re-added 2 the NewTable class back into the solution 1 and adding the migration worked fine.

Score: 1

If you are using web deployment from Visual 4 Studio sometimes doesn't delete the old 3 dlls. I had the same problem, change to 2 Web Deployment Package and didn't give me 1 problems.

Score: 0

I had a same problem in my asp.net website, to 6 resolve the problem I purposely added compile 5 time error in one of the cs file in the 4 app code by removing a semicolon, then I 3 rectified the compilation problem by adding 2 semicolon again.

This process caused application 1 to compile again.After this error got vanished.

Score: 0

The other cause of this problem, your add 7 model in any solution project and change 6 your model project.


--- WEB CONFIG -->Entity Connection


--- WEB CONFIG -->Entity Connection

Later, I think this structure 5 is bad and Change project.

using PROJECT.C;

using PROJECT.C;

--- APP.CONFIG -->Entity Connection

Everything was 4 fine but I get an error. Error Detail : The EntityContainer name must be unique. An EntityContainer with the name 'Entities' is already defined

Because I forgot 3 change Web.Config files.


    <add name="donatelloEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=donatello;persist security info=True;user id=1;password=1;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />


 <add name="donatelloEntities" connectionString="metadata=res://*/EntityModel.Model.csdl|res://*/EntityModel.Model.ssdl|res://*/EntityModel.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=donatello;user id=sa;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

This Problem 2 is Simple but may cause loss of time. I 1 wanted to give an example. I hope is useful.


Score: 0

To solve the issue Entity 6.2.0, VS 2017, single 3 edmx

I changed the name of my model.edmx 2 to another name, built the project, then 1 changed it back to the original name.

Score: 0

In my case, probably after merging a version 4 back, my startup project file (csproj) got 3 corrupted.

Al the Entity classes where added:

<Compile Include="Class.cs">

After 2 removing all relevant entries by hand the 1 problem was solved.

More Related questions