Getting database connection string in ASP.NET 5/EF 6

asp.net asp.net-core configuration entity-framework entity-framework-6

Accepted Answer

ZZZ_tmp
0
1/4/2016 3:20:19 AM

Popular Answer

I attempted @Ryan's second strategy, and it worked to some extent, but instantiatingDbContext simply including a connection stringSqlConnection In my situation, EDMX's classes are not Code First compatible, therefore when I ask EF to construct a Code First context, it will do so. Classes in the EDMX (poco, if you will) must support Code First; otherwise, they won't function.

My answer to this is to just addApp.config in the web project's file.

Although I don't enjoy this workaround, it must be done when using EF 6 and an ASP.NET 5 web project.

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="SomethingEntities" connectionString="metadata=res://*/Entities.Something.Entities.csdl|res://*/Entities.Something.Entities.ssdl|res://*/Entities.Something.Entities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\;initial catalog=Db_Local;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow