What is the simplest way to programmatically toggle back and forth between test and dev databases using the LINQ to SQL ORM?
When newing up a DataContext, one of the overloads takes a connection string. I would therefore have a compiler switch something like:
#if Debug
string connectionString = ....
#else
string connectionString = ...
#endif
DbDataContext db = new DbDataContext(connectionString);
Using a connection string in the web/app config. Have multiple configs for dev/test/prod. Each should have the appropriate connection string. Switch the config for each environment.
using (MyDataContext dc = new MyDataContext(connectionString) )
{
//do a unit of work.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With