LINQ to SQL - 在test和dev db之间切换的最佳方法

alc*_*cal 7 c# linq linq-to-sql

使用LINQ to SQL ORM以编程方式在测试数据库和开发人员数据库之间来回切换的最简单方法是什么?

BFr*_*ree 8

在新建DataContext时,其中一个重载采用连接字符串.因此我会有一个编译器开关,如:

 #if Debug
 string connectionString = ....
 #else
 string connectionString = ...
 #endif

 DbDataContext db = new DbDataContext(connectionString);
Run Code Online (Sandbox Code Playgroud)


tva*_*son 7

在web/app配置中使用连接字符串.有dev/test/prod的多个配置.每个都应该有适当的连接字符串.切换每个环境的配置.