假设我在web.config,web.debug.config和web.release.config中有这个
<connectionStrings>
<add name="MysqlDbContext_staging"
connectionString="info"
providerName="MySql.Data.MySqlClient" />
<add name="MysqlDbContext_production"
connectionString="info"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
public class MysqlDbContext: DbContext
{
#if DEBUG
public static string dbName = "MysqlDbContext_staging";
#else
public static string dbName = "MysqlDbContext_production";
#endif
public MysqlDbContext() : base(dbName)
{
}
}
}
我想要的是:
- 在调试模式下运行时,有一些方法可以切换它们
- 在发布模式下运行时,有一些方法可以切换它们
这样我就不必在每次调试它们之一时都需要在连接字符串中编辑数据库的名称。
不确定是否可以通过配置管理器在编译项目时添加另一种“调试”选项来实现此目的。