Entity Framework : Change connection string at runtime

后端 未结 6 1762
半阙折子戏
半阙折子戏 2021-02-04 03:06

Assuming there is an ASP.NET MVC application that uses Entity Framework 6 with code-first approach and StructureMap as IoC.
Also It uses Unit Of Work pattern. Here are the c

6条回答
  •  青春惊慌失措
    2021-02-04 03:33

    The two approaches are good for two different situations:

    • The transform is good for deploying a connection string that only changes for the different evironments (test, production).

    • The approach of adding a constructor (which takes the connection string name) in a separate file to extend the partial dbcontext class allows the connection to be switched at runtime.

提交回复
热议问题