开发者

NOLOCK with Linq to SQL without setting Transaction IsolationLevel

Is there a way to use NOLOCK on a LIN2SQL single 开发者_运维百科query without setting the Transaction IsolationLevel? I need to do this as the query part of a larger (distributed) transaction.

For example:

using (var txn = new TransactionScope())
{

    // query1
    // query2
    // query3
}

I want the changes of query 1 and 3 to be transactional, but I need NOLOCK on query2, which happens to be on a separate db to the other queries. If I re-set the transaction scope for query2 to ReadUncommitted then I get the error:

The transaction specified for TransactionScope has a different IsolationLevel than the value requested for the scope. Parameter name: transactionOptions.IsolationLevel


Will it work for you?

 using (var txn = new TransactionScope())
 {

    // query1
     using (TransactionScope txn2 = 
     new TransactionScope(TransactionScopeOption.RequiresNew),
     new TransactionOptions() {//isolation level,timeout, etc}
     )
     {
    // query2
      }
    // query3
  }


How about making query2 a stored procedure, with nolock in the sql, and calling that from Linq2Sql?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜