Sql 有没有办法将两个数据库置于调试和发布配置中,并在调试和发布模式的两个数据库之间切换?
假设我在web.config、web.debug.config和web.release.config中都有这个Sql 有没有办法将两个数据库置于调试和发布配置中,并在调试和发布模式的两个数据库之间切换?,sql,asp.net-mvc,Sql,Asp.net Mvc,假设我在web.config、web.debug.config和web.release.config中都有这个 <connectionStrings> <add name="MysqlDbContext_staging" connectionString="info" providerName="MySql.Data.MySqlClient" /> <add name="MysqlDbContext_produ
<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)
{
}
}
}
公共类MysqlDbContext:DbContext
{
#如果调试
公共静态字符串dbName=“MysqlDbContext\u staging”;
#否则
公共静态字符串dbName=“MysqlDbContext\u production”;
#恩迪夫
public MysqlDbContext():base(dbName)
{
}
}
}
我想要的是:
不确定是否有办法在编译项目时使用Configuration Manager添加另一个调试选项。在Configuration Manager中添加了另一个配置 为该配置定义新的调试宏并添加
#elif debug_production
public static string dbName = "MysqlDbContext_production";