Entity Framework error - “The EntityContainer name must be unique”

前端 未结 10 2326
南旧
南旧 2021-02-07 09:24

We have a solution which consists of two projects - a console application project and a web application project. Each of these has an identical in schema, but differently named

相关标签:
10条回答
  • 2021-02-07 09:44

    Note when trying to rename a entity container to that of a previously deleted entity container, you will need to go into your web.config or app.config and delete the connection string out of the configuration section.

    0 讨论(0)
  • 2021-02-07 09:45

    Change the webconfig file entity connection string entry from this

    metadata=res://*/App_Code.AAA.csdl|res://*/App_Code.AAA.ssdl|res://*/App_Code.AAA.msl;provider=System.Data.SqlClient;provider connection string="data source=XXX;initial catalog=XXX;user id=XXX;password=XXX;multipleactiveresultsets=True;App=EntityFramework"" 
    providerName="System.Data.EntityClient
    

    to

    metadata=res://MyProject/App_Code.AAA.csdl|res://MyProject/App_Code.AAA.ssdl|res://MyProject/App_Code.AAA.msl;provider=System.Data.SqlClient;provider connection string="data source=XXX;initial catalog=XXX;user id=XXX;password=XXX;multipleactiveresultsets=True;App=EntityFramework"" 
    providerName="System.Data.EntityClient
    
    0 讨论(0)
  • 2021-02-07 09:45

    Just in case anyone else is desperate and not finding any answers - I accidentally ended up with a copy of my .edmx file included in the project in a second location. Both were being included in the build.

    ;-)

    If this happened to you, fear not: You were not the first.

    0 讨论(0)
  • 2021-02-07 09:45

    I fixed this issue in EntityFramework 6.0 by.

    1. During creation of the models, I name the .edmx to the name of the entities. i.e. (MYDbEntities)

    2. After creation i open the MYDbEntities.Context.cs and modified the "Entities" Class to "MYDbEntities".

    3. Open the App.Config and look for the connection string
    4. Open the MYDbEntities.Context.cs and change the connection string to Connection string from the config. example "MyDbConnection"
    5. Make sure that the connection string is like this

      metadata=res:///MYDbEntities.csdl|res:///MYDbEntities.ssdl|res://*/MYDbEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=YourDb;persist security info=True;user id=sa;password=Sw0rdf!sh;multipleactiveresultsets=True;application name=EntityFramework"

    Note: my entities resides in a separate DLL.

    Hope this helps.

    0 讨论(0)
  • 2021-02-07 09:52

    In my case none of the solutions worked. I finally recycled the IIS on my hosting to make it work. Hope this helps someone :)

    0 讨论(0)
  • 2021-02-07 09:56

    Well, in my case I'm working diferent software architecture, because I have diferent projects (dlls), they access to the same Database, but I have diferent entities inside. So, when I have references in a project that needs all or at least two of them, i get this error

    If I change the Entity Container Name on each one, I solve the problem, but now my connection string are diferent and I have to include all the connection strings in the config file for each dll I refer.

    0 讨论(0)
提交回复
热议问题