LINQ к SQL - лучший способ переключиться между тестом и dev дб

, не объявляя переменную или подобное, трудно ссылаться на вводимое жестко закодированное значение. Если это ваша цель, вы должны рассмотреть решение Даниэля Хилгарта. Обычно вы будете иметь значение под рукой. В таком случае, вот как вы могли бы это сделать.

declare @t table (col1 varchar(10))

insert @t values ('hello')
insert @t values ('bye')

declare @newvalueforallrows varchar(10)
set @newvalueforallrows = 'hello'

update @t set col1 = @newvalueforallrows
where col1 <> @newvalueforallrows

-- 1 row updated
7
задан alchemical 8 June 2009 в 18:00
поделиться

3 ответа

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);
8
ответ дан 6 December 2019 в 11:52
поделиться

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.

7
ответ дан 6 December 2019 в 11:52
поделиться
using (MyDataContext dc = new MyDataContext(connectionString) )
{
  //do a unit of work.
}
2
ответ дан 6 December 2019 в 11:52
поделиться
Другие вопросы по тегам:

Похожие вопросы: