更改实体框架DBContext的DB名称
我继承了一个使用实体框架访问SQL Server数据库的应用程序。 dbContext
类具有构造函数,如下所示,其中building permits
是初始目录的名称。
我希望能够通过配置文件在数据库(具有相同连接)之间切换,而不是更改代码。
我该怎么做?
public BuildingPermitsDbContext() : base("BuildingPermits")
{
Database.SetInitializer<BuildingPermitsDbContext>(null);
}
I have inherited an application which is using Entity Framework to access a SQL Server database. The DbContext
class has the constructor as shown below, where BuildingPermits
is the name of the initial catalog.
I would like to be able to switch between databases (with the same connection) via a config file instead of changing the code.
How can I accomplish this?
public BuildingPermitsDbContext() : base("BuildingPermits")
{
Database.SetInitializer<BuildingPermitsDbContext>(null);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试一下。
You can try this.