如何防止SqlServer数据库死锁
1.sql 语句加上with(nolock)
例:select * from tableA with(nolock) where ...
2.EntityFramework
//with(nolock) 在EF中的使用方法
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadUncommitted }))
{
try
{
function();
}
finally
{
ts.Complete();
}
}
3.加索引