For a little background:
I have a DLL project with the following structure:
Rivworks.Model (project)
\\Negotiation (folder)
Model.edmx
The other cause of this problem, your add model in any solution project and change your model project.
--PROJECT A --> MODEL.EDMX
--- WEB CONFIG -->Entity Connection
--PROJECT B
--- WEB CONFIG -->Entity Connection
Later, I think this structure is bad and Change project.
--PROJECT A
using PROJECT.C;
WEB.CONFIG - USE PROJECT C APP.CONFIG CONNECTIONSTRING
--PROJECT B
using PROJECT.C;
WEB.CONFIG - USE PROJECT C APP.CONFIG CONNECTIONSTRING
--PROJECT C (CLASS LIBRARY) --> MODEL.EDMX
--- APP.CONFIG -->Entity Connection
Everything was 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 change Web.Config files.
OLD WEB.CONFIG
<add name="donatelloEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=donatello;persist security info=True;user id=1;password=1;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
NEW WEB.CONFIG
<add name="donatelloEntities" connectionString="metadata=res://*/EntityModel.Model.csdl|res://*/EntityModel.Model.ssdl|res://*/EntityModel.Model.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=donatello;user id=sa;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
This Problem is Simple but may cause loss of time. I wanted to give an example. I hope is useful.
Thanks.
To solve the issue Entity 6.2.0, VS 2017, single edmx
I changed the name of my model.edmx to another name, built the project, then changed it back to the original name.
I have found a way to save multiple containers with the same name (namespaced of course).
In EF5 and VS2012 you can set three different namespaces. First you can click on the edmx file in the solution browser and in the properties windows you can set the "Custom Tool Namespace", you can click on the *.Context.tt file right below the edmx and set another namespace there, and finally thanks to a lead from Mr Stuntz awesome answer I realized that by opening the edmx file and clicking in the white space you get another namespace field under Schema in the properties window.
Think we're done, not quite, I know you can see the Entity Container Name field and will try to change the name there but that doesn't seem to work, you get a little error that pops up. Ensure that all your edmx files have an individual namespace there. (I ensured I had a unique namespace in all three places)
Then go to your Model Browser and right click on EntityContainer: Entity to go to properties and change the name of your container(s). From that window with the namespace set everywhere I was able to get multiple contexts with the same name. I was dealing with things like blahcontext and blahcontextcontainer all of a sudden even though they were in different folders.
When you see that its a namespace problem. Or lack thereof.
I renamed my project but the old file was still in the bin folder. I just had to delete the old DLL from the bin folder.
I had the problem too but my solution was to clean the bin directory and then remove the connection string with the entity container name. Then I could rename my entities and put back the connection string.
I just ran into this. It looks like somehow Entity Framework got into a bad state in terms of what tables it thought it needed to add.
Normally EF will not recognize that a new table has to be created until you put the line
public virtual DbSet<NewTable> NewTable { get; set; }
inside your context class.
However, EF somehow got into a bad state where the mere presence of the NewTable class in my solution was triggering it to think that it needed to generate that table. So by the time the above line in the context triggered it to create a NewTable table, it already thought it had done it, hence the error about duplicate entities.
I just removed the NewTable class from my solution, commented things out so it would compile again (thankfully there wasn't too much of this), then added a new migration to make sure it was blank as it should have been. Then once things were back into a more predictable state, I re-added the NewTable class back into the solution and adding the migration worked fine.