我需要使用TransactionScope来读取NOLOCK,代码如下:
我希望在SQL查询中添加NOLOCK(查看SQL Profiler和自定义DbCommandInterceptor,但没有找到...)
更新:经过更多的研究,我想知道是否仍然使用了所选的游标,只是没有使用NOLOCK "hint"(仅适用于SQL Server,也仅适用于一个表),我找到了一些代码,可以获取当前事务,并且它似乎显示了正确的选定事务隔离级别(ReadUncommitted / Serializable等)。我仍然想测试它,但如果你有任何想法,请让我知道。 获取当前.net TransactionScope IsolationLevel
我缺少什么?
我正在尝试使用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 Profiler和自定义DbCommandInterceptor,但没有找到...)
更新:经过更多的研究,我想知道是否仍然使用了所选的游标,只是没有使用NOLOCK "hint"(仅适用于SQL Server,也仅适用于一个表),我找到了一些代码,可以获取当前事务,并且它似乎显示了正确的选定事务隔离级别(ReadUncommitted / Serializable等)。我仍然想测试它,但如果你有任何想法,请让我知道。 获取当前.net TransactionScope IsolationLevel
Transaction trans = Transaction.Current;
System.Transactions.IsolationLevel level = trans.IsolationLevel;
LogService.Instance.Debug($"Transaction IsolationLevel = {level.ToString()}");