以下内容为转载:

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. php大力力 [021节]mysql表名在mac下不能大写

    2015-08-27 php大力力021.mysql表名在mac下不能大写 刚才数据库里面,phpMyAdmin狂出错. Some errors have been detected on the s ...

  2. HTML的盒子模型

    每个HTML元素都可以看作一个装了东西的盒子,盒子具有宽度(width)和高度(height),盒子里面的内容到盒子的边框之间的距离即填充(padding),盒子本身有边框(border),而盒子边框 ...

  3. grunt 执行

    几天以前,我决定开始启用一个CSS预处理器,找了很久,我选择了SASS并且尝试着去安装它.但是这似乎不是一件简单的事,在安装过程中出现了许多让我始料不及的问题,我很沮丧,但查找了很多资料,我终于找到了 ...

  4. swift SDWebImage使用

    Web image(网络图像) 该库提供了一个支持来自Web的远程图像的UIImageView类别它提供了: 添加网络图像和缓存管理到Cocoa Touch framework的UIImageView ...

  5. post&get请求总结

    1.将get获取的数据,UrlDecode后返回 public static string SendGet(string url) { HttpWebRequest httpWebRequest = ...

  6. Bat脚本处理ftp超强案例解说

    Bat脚本处理ftp超强案例解说 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://369369.blog.51cto.com/31 ...

  7. Nginx启动出错 error while loading shared libraries:

    在centos5.7 32位上编译安照 nginx-1.1.16 出错 [root@localhost conf]# /usr/local/nginx/sbin/nginx/usr/local/ngi ...

  8. buildroot ntp 网络时钟同步

    /********************************************************************** * buildroot ntp 网络时钟同步 * 说明: ...

  9. Aborting commit: 'XXXXXXXX'remains in conflict错误

    今天在提交项目文件到本地SVN时提示错误如下: 过期:”global.php“在事务”21-1“, You have to update your working copy first. 运行upda ...

  10. How to migrate from VMware and Hyper-V to OpenStack

    Introduction I migrated >120 VMware virtual machines (Linux and Windows) from VMware ESXi to Open ...