如何指定数据库隔离级别被使用,在较高的水平?较高、级别、水平、数据库

2023-09-05 02:53:26 作者:自找的痛ゝ就别喊疼

我使用的TransactionScope s的高层次来包装一些高级别code,使一些连接到数据库。

I am using TransactionScopes at a high level to wrap some high level code that makes a number of connections to the database.

一个我所说的功能是用于只读功能,其中一个未提交读隔离级别需要一个通用的读取。但在某些情况下,它被用作大型更新操作部分和提交读会更适合。

One of the functions I call is a generic read that is used for read only functions where a read uncommitted isolation level is needed. But in some cases it is used as part of large update operation and a read committed would be more suitable.

目前的最高水平,我打电话内的事务范围的职能,我应该能够设置隔离级别的事务?

At the highest level where I am calling my functions inside a transaction scope, should I be able to set the Isolation Level for the transaction?

推荐答案

您可以通过设定不同的TransactionScope本身的隔离级别。那是什么意思?

You can set the isolation level on the TransactionScope itself. Is that what you mean?

using (var txn = new TransactionScope(
    TransactionScopeOption.Required, 
    new TransactionOptions
    {
        IsolationLevel = IsolationLevel.ReadUncommitted
    }
))
{
    // Your LINQ to SQL query goes here
}

(code,从我的博客文章这里。)