NOLOCK with Linq to SQL

后端 未结 5 634
小鲜肉
小鲜肉 2020-11-30 23:01

Is it possible to get Linq2Sql to emit a NOLOCK in its SQL? And if so, how?

5条回答
  •  鱼传尺愫
    2020-11-30 23:20

    Here is an extension method to use with LINQPAD

        public static IQueryable Dump2(this IQueryable query)
    {
        using (var txn = new System.Transactions.TransactionScope(TransactionScopeOption.RequiresNew, 
            new TransactionOptions
            {       
                IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
            }))
        {
            return query.Dump();
        }   
    }
    

    Then you can call it as:

    MyTable.Where(t => t.Title = "Blah").Dump2();
    

提交回复
热议问题