在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 ...
随机推荐
- LeetCode222 Count Complete Tree Nodes
对于一般的二叉树,统计节点数目遍历一遍就可以了,但是这样时间复杂度O(n),一下就被卡住了. 这题首先要明白的是,我们只需要知道叶子节点的数目就能统计出总节点树. 想法1: 既然是完全二叉树,我肯定是 ...
- C++ algorithm 里的sort函数应用
MSDN中的定义: template<class RanIt> void sort(RanIt first, RanIt last); //--> 1)template< ...
- Objects and Data Structures
Date Abstraction Hiding implementation is not just a matter of putting a layer of fucntions between ...
- Chocolate_DP
Description In 2100, ACM chocolate will be one of the favorite foods in the world. "Green, oran ...
- HDU 1811
http://acm.hdu.edu.cn/showproblem.php?pid=1811 中文码题 对于等号的情况,用并查集合并(因为编号不同一定可以分出先后) 然后判断能否构成拓扑排序,以及拓扑 ...
- SQL备份还原,分离附加
备份.还原.分离.附加 备份:在要备份的数据库上右键点击任务,在选择备份.在打卡的对话框中根据需要选择.注意:备份过期时间不能为0,否则会马上过期.目标可根据需要放在任何位置.最后,点击确定,备份成功 ...
- 第一个demo
1.首先这是最初的概念模型. 2.最后设计成这样. 3.运行
- OpenvSwitch架构
Openvswitch的架构 数据库结构和OVS-VSCTL # ps aux | grep openvswitch root 1117 0.0 0.0 21200 1580 ? ...
- debug进入线程中
今天debug调试程序时,怎么也进入不了线程中,f5直接进源码,f6直接跳过了,后来把断点打在线程的Run()方法里面,按f8(可能要多按几次)就可以了.
- hilbert矩阵
希尔伯特矩阵 希尔伯特矩阵是一种数学变换矩阵 Hilbert matrix,矩阵的一种,其元素A(i,j)=1/(i+j-1),i,j分别为其行标和列标. 即: [1,1/2,1/3,……,1/n] ...