以下内容为转载:

A:https://dotblogs.com.tw/asdtey/2009/09/27/10793

B:http://www.gitshah.com/2014/08/how-to-add-nolock-hint-to.html

 

1,方法一   使用 TransactionScope

2,  使用 ObjectContext.Connection.BeginTransaction

  

using (TestEntities te = new TestEntities()) {

////方法二 ////此方法會修改所有操作的交易層級 te.Connection.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);

var users = te.User.Select(a => a).ToList();

}

 

3,重写 DbCommandInterceptor

public class NoLockInterceptor : DbCommandInterceptor

{

private static readonly Regex _tableAliasRegex =

new Regex(@"(?<tablealias>AS \[Extent\d+\](?! WITH \(NOLOCK\)))",

RegexOptions.Multiline | RegexOptions.IgnoreCase);

[ThreadStatic]

public static bool ApplyNoLock;

public override void ScalarExecuting(DbCommand command,

DbCommandInterceptionContext<object> interceptionContext)

{

if (ApplyNoLock)

{

command.CommandText =

_tableAliasRegex.Replace(command.CommandText,

"${tableAlias} WITH (NOLOCK)");

}

}

public override void ReaderExecuting(DbCommand command,

DbCommandInterceptionContext<dbdatareader> interceptionContext)

{

if (ApplyNoLock)

{

command.CommandText =

_tableAliasRegex.Replace(command.CommandText,

"${tableAlias} WITH (NOLOCK)");

}

}

}

3.1

NoLockInterceptor.ApplyNoLock = true;

3.2

DbInterception.Add(new NoLockInterceptor());

在EntityFramework中使用 nock的方法。的更多相关文章

  1. EntityFramework 中支持 BulkInsert 扩展

    本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 前言 很显然,你应该不至于使用 EntityFramework 直接插入 10W 数据到数据库中,那 ...

  2. EntityFramework中支持BulkInsert扩展(转载)

    前言 很显然,你应该不至于使用 EntityFramework 直接插入 10W 数据到数据库中,那可能得用上个几分钟.EntityFramework 最被人诟病的地方就是它的性能,处理大量数据时的效 ...

  3. EntityFramework中支持BulkInsert扩展

    EntityFramework中支持BulkInsert扩展 本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 前言 很显然,你应该不至于使用 Ent ...

  4. EntityFramework中的线程安全,又是Dictionary

    继上次记一次w3wp占用CPU过高的解决过程(Dictionary和线程安全)后又再次与Dictionary博弈,这一次是在EntityFramework中的Dictionary. 从一个异常说起 这 ...

  5. 工作总结 EntityFramework中出现DateTime2异常的完美解决办法

    EntityFramework中出现DateTime2异常的完美解决办法   今天在使用entityframework往数据库插入数据的时候,突然出现了一个数据类型转换异常的问题: System.Da ...

  6. [转]EntityFramework中常用的数据修改方式

    本文转自:http://blog.csdn.net/itmaxin/article/details/47662151 上一篇文章里提到了 EntityFramework中常用的数据删除方式,那么修改对 ...

  7. 设置EntityFramework中decimal类型数据精度问题(EF默认将只会保留到2为精度)

    原文:设置EntityFramework中decimal类型数据精度 EF中默认的decimal数据精度为两位数,当我们数据库设置的精度大于2时,EF将只会保留到2为精度. e.g. .19990将会 ...

  8. EntityFramework中经常使用的数据改动方式

    上一篇文章里提到了 EntityFramework中经常使用的数据删除方式.那么改动对象值也有多种方式 第一种 相同是官方推荐的方式,先查询出来,再对要改动的字段赋值,这也应该是用的比較多的. 另外一 ...

  9. JavaScript中Math对象的方法介绍

    1.比较最值方法 比较最值有两种方法,max() 和 min() 方法. 1.1 max() 方法,比较一组数值中的最大值,返回最大值. var maxnum = Math.max(12,6,43,5 ...

随机推荐

  1. 算法----序列和的 top N

    Description: 两个长度为 n 的数组 A 和 B, 各从中选出一个元素相加 A[i] + B[j], 求 top n 小的那些和. 思路 1:这样的和总共有 n^2 个, 排序,然后取前 ...

  2. ubuntu下的wps不能使用中文.

    首先如果wps不能用中文的话应该是 excell ppt word 都不能用 . 我的办法需要改三个文件 . 先后打开这三个文件 . xpower@xpower-CW65S:~$ sudo vim / ...

  3. setuptools,pip,install,UnicodeDecodeError: 'ascii' codec can't decode byte.原因和解决方案

    昨天重装Python2.7.6时,为了安装第三方库,我去下pip.为了装pip,又得先装 ez_setup.py.结果装ez_setup时,遇到了问题,报错: UnicodeDecodeError:  ...

  4. JQuery源码分析(八)

    jQuery的each迭代器 jQuery的each方法从使用上就要分2种情况: $.each()函数 $(selector).each() $.each()函数和$(selector).each() ...

  5. 2、SQL基础整理(聚合函数)

    聚合函数 --求平均 select  AVG(age) as 年龄 from xuesheng select AVG(chinese) as 语文 from xuesheng where class ...

  6. iOS-Block两个界面传值

    先说一下思路: 首先,创建两个视图控制器,在第一个视图控制器中创建一个Label和一个Button,其中Label是为了显示第二个视图控制器传过来的字符串, Button是为了push到第二个界面. ...

  7. H - 放苹果

      Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Des ...

  8. 《JavaScript Ninja》之正则表达式

    正则表达式 是一个拆分字符串并查询相关信息的过程. 练习网站:JS Bin 正则表达式测试网站:Regular Expression Test Page for JavaScript 正则表达式进修 ...

  9. android webview如何加载asset目录里的页面

    在asset里的页面都可以这样获得 file:///android_asset/index.html

  10. Java 返回一个整数的各个数字之和的一种方法

    public static long sumDigits(long n){ long total=0; long number=n; while(number!=0){ total=total+num ...