.NET 4: How to configure EDMX file in other assembly in Web.Config

后端 未结 3 1314
心在旅途
心在旅途 2020-12-17 23:41

I have a problem with configuring an EDMX file that lives in an other assembly than by web project. My project looks somewhat like this:

Project 1
--> Dat         


        
相关标签:
3条回答
  • 2020-12-18 00:23

    Easier way is to take connection string from Web.Config and copy them into App.Config and point EDMX's connectionstring to same DB information. e.g

      <connectionStrings>
        <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
        <add name="aspnetdbEntities" connectionString="metadata=res://*/Data.PSBData.csdl|res://*/Data.PSBData.ssdl|res://*/Data.PSBData.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\aspnetdb.mdf;integrated security=True;user instance=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
    

    Also you need to check if the namespaces are correct if you have moved Database.edmx from Project 2 to Project 1, which you can check by opening Database.edmx and goto code behind.

    0 讨论(0)
  • 2020-12-18 00:24

    You have to change the * in the connection string for the assembly name where the .edmx files are in:

    <add name="Entities" connectionString="metadata=res://*/Models.EF.Model.csdl|res://*/Models.EF.Model.ssdl|res://*/Models.EF.Model.msl;provider=System.Data.SqlClient;provider connection ... ;" providerName="System.Data.EntityClient" />
    

    for

    <add name="Entities" connectionString="metadata=res://Project2/Models.EF.Model.csdl|res://Project2/Models.EF.Model.ssdl|res://Project2/Models.EF.Model.msl;provider=System.Data.SqlClient;provider connection ... ;" providerName="System.Data.EntityClient" />
    
    0 讨论(0)
  • 2020-12-18 00:32

    As it turned out, there were 2 problems. One was solved replacing the * in the connection string.

    The second problem was the one described here: http://blogs.teamb.com/craigstuntz/2010/08/13/38628/

    It had to do with the path .csdl, .ssdl and .msl files had as resources inside the Project1 assembly

    Anyway, things function properly now

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