- A+
sql实现方法:
select * from 表名(nolock) 加上(nolock)
EF实现办法:
程序集引用 System.Transactions 看下面代码
---我这里用了封装的委托的写法---
public static void NoLockInvokeDB(Action action)
{
var transactionOptions = new System.Transactions.TransactionOptions();
transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
{
try
{
action();
}
finally
{
transactionScope.Complete();
}
}
}
---使用实例---
public void test(){
NoLockInvokeDB(() =>
{
using (var ctx = new ShopElfEntities())
{
var user=ctx.user.tolis();
}
});
}
注意:只需要在方法最外面一层用就好了,里面嵌套的方法就不需要再用了