我已經做了SQL 2008 R2和Entity Framework 4 以下測試(數據庫對READ_COMMITTED_SNAPSHOT選項)
我創建了以下存儲過程返回上下文隔離級別(原從here):
Create Procedure TempTestIsolation
AS
Begin
DECLARE @UserOptions TABLE(SetOption varchar(100), Value varchar(100))
INSERT @UserOptions
EXEC('DBCC USEROPTIONS WITH NO_INFOMSGS')
SELECT Value
FROM @UserOptions
WHERE SetOption = 'isolation level'
End
然後我編寫了以下測試:
static void Main(string[] args)
{
var entities = new MyEntities();
// Execute the SP to get the isolation level
string level = entities.TempTestIsolation().First().Value;
Console.WriteLine("Without a transaction: " + level);
var to = new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.Snapshot };
using (var ts = new TransactionScope(TransactionScopeOption.Required, to))
{
// Execute the SP to get the isolation level
level = entities.TempTestIsolation().First().Value;
Console.WriteLine("With IsolationLevel.Snapshot: " + level);
}
to = new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted };
using (var ts = new TransactionScope(TransactionScopeOption.Required, to))
{
// Execute the SP to get the isolation level
level = entities.TempTestIsolation().First().Value;
Console.WriteLine("With IsolationLevel.ReadCommitted: " + level);
}
Console.ReadKey();
}
衛生組織Ë產量爲:
正如你所看到的,當你在你TransactionOptions設置的IsolationLevel到快照,存儲過程的「快照」隔離級別下執行,並不下「讀取提交的快照「。
相反,如果你設置了的IsolationLevel到READCOMMITTED它正在執行 「讀提交快照」。
希望它有幫助。
瞭解。我想我的問題確實是LLBLGen的問題之一。該工具需要在構建Transaction實例時提供IsolationLevel。需要了解什麼值會導致庫使用數據庫的默認值。 –