私は何が欠けていますか?
次のような TransactionScope を使用して NOLOCK で読み取ろうとしています。
var scopeOptions = new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted };
using (var scope = new TransactionScope(TransactionScopeOption.Required, scopeOptions))
{
using (var db = new MyDbContext(ConnectionStringEntities))
{
// Simple read with a try catch block...
}
scope.Complete();
}
SQLクエリにNOLOCKが追加されていることを期待していました(SQLプロファイラーとカスタムDbCommandInterceptorを調べましたが、そこにはありません...
更新:さらに調査した結果、NOLOCK の「ヒント」(SQL Server 固有 - また、1 つのテーブルのみに固有) なしで、選択したカーソルが結局使用されているのではないかと思います。現在のトランザクションを取得するコードをいくつか見つけて、正しく選択されたトランザクションの分離 (ReadUncommitted / Serializable など) が表示されているようです。まだテストしたいのですが、ご意見があればお知らせください。
現在の .net TransactionScope IsolationLevel を取得する
Transaction trans = Transaction.Current;
System.Transactions.IsolationLevel level = trans.IsolationLevel;
LogService.Instance.Debug($"Transaction IsolationLevel = {level.ToString()}");