EF Core query inside ReadUncomitted transaction scope, executed as ReadComitted

50 Views Asked by At

I open a transaction scope with IsolationLevel = IsolationLevel.ReadUncommitted (I need to execute a non blocking query). Inside the transaction, I execute a query on an injected dbContext (.NET Core 3.1 with EF Core 3.1). I would expect the query to execute as a ReadUncomitted, but inspecting SQL Server Profiler, I see the following 2 relevant lines:

enter image description here

Inside the "login" line, is the following:

enter image description here

The line with "exec sp_exe....." has my query.

The relevant lines of code are:

using (var tx = this.Transactions.Required())
{
    var query = await this.Uow.MyEntity.MyQuery(myParameter);

    if (query != null)
    {
        ...do something
    }

    await this.Transactions.CompleteAsync(tx);
}

and

public System.Transactions.TransactionScope Required()
{
    var transactionOptions = new System.Transactions.TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted };
    transactionOptions.Timeout = TimeSpan.FromHours(2);
    return new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions, System.Transactions.TransactionScopeAsyncFlowOption.Enabled);
}

I am I missing something? All examples of using the TransactionScope show the dbContext created inside the TS, but in my case, dbContext is injected.

Any guidance will be greatly appreciated.

0

There are 0 best solutions below