Entity Framework 6 set connection string runtime

后端 未结 3 721
日久生厌
日久生厌 2020-12-08 07:50

We are in a mixed environment where our application is using both ADO.NET and Entity Framework.
Since both are pointing to the same physical SQL server, we would like to

3条回答
  •  遥遥无期
    2020-12-08 08:14

    Other way is to declare another connection string in the config file and use it with the following alternative constructor:

    class TestEntities : DbConnect {
     
        public TestEntities (string connectionName)
           : base($"name={connectionName}")
        {
        }
    
    ...
    

    Then to use this solution just:

    1. add another connection to the config file:
     
    
    1. call it like this:

      var db = new TestEntities (connectionName:"other");
      

提交回复
热议问题