LINQ TO SQL を使用して、既存のトランザクション内で分離レベル read uncommitted でクエリを実行しようとしています。親トランザクションからこのトランザクションを抑制するオプションを使用すると、分離レベルを指定できなくなるようです。LINQPad でこのコードを使用する:
void Main()
{
var db = this;
db.ExecuteQuery<string>(@"SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
using (var trans = new TransactionScope(TransactionScopeOption.Required))
{
// updates or inserts here
using (new TransactionScope(TransactionScopeOption.Suppress,
new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted }))
{
db.ExecuteQuery<string>(@"SELECT CASE transaction_isolation_level
WHEN 0 THEN 'Unspecified'
WHEN 1 THEN 'ReadUncomitted'
WHEN 2 THEN 'Readcomitted'
WHEN 3 THEN 'Repeatable'
WHEN 4 THEN 'Serializable'
WHEN 5 THEN 'Snapshot' END AS TRANSACTION_ISOLATION_LEVEL
FROM sys.dm_exec_sessions
where session_id = @@SPID
").Dump("Inside the transaction");
}
// updates or inserts here
}
}
SERIALIZABLE の結果を取得します。トランザクション内でクエリを実行し、分離レベルをコミットされていない読み取りに変更する方法はありますか?