在EntityFramework中使用 nock的方法。
以下内容为转载:
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的方法。的更多相关文章
- EntityFramework 中支持 BulkInsert 扩展
本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 前言 很显然,你应该不至于使用 EntityFramework 直接插入 10W 数据到数据库中,那 ...
- EntityFramework中支持BulkInsert扩展(转载)
前言 很显然,你应该不至于使用 EntityFramework 直接插入 10W 数据到数据库中,那可能得用上个几分钟.EntityFramework 最被人诟病的地方就是它的性能,处理大量数据时的效 ...
- EntityFramework中支持BulkInsert扩展
EntityFramework中支持BulkInsert扩展 本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 前言 很显然,你应该不至于使用 Ent ...
- EntityFramework中的线程安全,又是Dictionary
继上次记一次w3wp占用CPU过高的解决过程(Dictionary和线程安全)后又再次与Dictionary博弈,这一次是在EntityFramework中的Dictionary. 从一个异常说起 这 ...
- 工作总结 EntityFramework中出现DateTime2异常的完美解决办法
EntityFramework中出现DateTime2异常的完美解决办法 今天在使用entityframework往数据库插入数据的时候,突然出现了一个数据类型转换异常的问题: System.Da ...
- [转]EntityFramework中常用的数据修改方式
本文转自:http://blog.csdn.net/itmaxin/article/details/47662151 上一篇文章里提到了 EntityFramework中常用的数据删除方式,那么修改对 ...
- 设置EntityFramework中decimal类型数据精度问题(EF默认将只会保留到2为精度)
原文:设置EntityFramework中decimal类型数据精度 EF中默认的decimal数据精度为两位数,当我们数据库设置的精度大于2时,EF将只会保留到2为精度. e.g. .19990将会 ...
- EntityFramework中经常使用的数据改动方式
上一篇文章里提到了 EntityFramework中经常使用的数据删除方式.那么改动对象值也有多种方式 第一种 相同是官方推荐的方式,先查询出来,再对要改动的字段赋值,这也应该是用的比較多的. 另外一 ...
- JavaScript中Math对象的方法介绍
1.比较最值方法 比较最值有两种方法,max() 和 min() 方法. 1.1 max() 方法,比较一组数值中的最大值,返回最大值. var maxnum = Math.max(12,6,43,5 ...
随机推荐
- golang函数调用计时
package main import ( "log" "time" ) func f() { defer timeoutCheck("f slow& ...
- 在MyEclipse上搭建web服务器
a) Servlet是什么? Servlet(服务器端小程序)是使用Java语言编写的服务器端程序[o1] ,可以使用脚本语言,生成动态的web页. b) Servlet的架构? ...
- LeetCode----3 Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...
- BZOJ 3163 Eden的新背包问题
分治背包+单调队列优化. 但是为什么maxn要1w多?...不怎么懂. #include<iostream> #include<cstdio> #include<cstr ...
- Android 中如何获取 H5 保存在 LocalStorage 的数据
主要分三步: 写个接口,接收 Js 回调 添加到 WebView 主动调用 Js 获取 比如我要获取保存在 LocalStorage 中的 userKey 字段: 1.写个接口,接收 Js 回调 pu ...
- url重写技术
URL 重写是截取传入 Web 请求并自动将请求重定向到其他 URL 的过程.比如浏览器发来请求 hostname/101.aspx ,服务器自动将这个请求中定向为http://hostname/li ...
- RegexKitLite 正则表达式
http://blog.csdn.net/zzfsuiye/article/details/6631466(转--讲得不错) 最 近做一个项目遇到从NSString中获取当中的IP地址使用 Regex ...
- What are the 10 algorithms one must know in order to solve most algorithm challenges/puzzles?
QUESTION : What are the 10 algorithms one must know in order to solve most algorithm challenges/puzz ...
- 三步搞定ISO/GHO安装系统 - imsoft.cnblogs
高清互动安装系统附件:重装系统视频教程.7z
- activiti 任务授权,把流程中当前任务授权个其他用户代为办理
/ * 授权代办 * @param serDoc / @Transactional(readOnly = false) public void authAgent(SerDoc serDoc) { S ...