sql實現方法: sql
select * from 表名(nolock) 加上(nolock) ui
EF實現辦法: spa
程序集引用 System.Transactions 看下面代碼it
---我這裏用了封裝的委託的寫法---io
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();
}
}
}test
---使用實例---select
public void test(){引用
NoLockInvokeDB(() =>
{程序
using (var ctx = new ShopElfEntities())
{方法
var user=ctx.user.tolis();
}
});
}
注意:只須要在方法最外面一層用就行了,裏面嵌套的方法就不須要再用了