Entity Framework: how to find transaction isolation level in SQL Profiler?

entity-framework entity-framework-6 sql-server sql-server-2012 transactions

Question

BeginTransaction method is used to manage transactions in Entity Framework 6. It allows to set isolation level for transaction as you may see in code below (just a sample):

using (var context = new DataContext())
{
    using (var transaction = context.Database.BeginTransaction(IsolationLevel.Serializable))
    {
        context.Entities.Add(new Entity());

        context.SaveChanges();

        transaction.Commit();
    } 
}

The problem is: when I use SQL Server Profiler, I cann't find any information about isolation level for real SQL transaction.

Attempt #1:

I tried to trace ALL kinds of events and search by "isolation" keyword in trace results. Only two events I found:

EventClass          TextData
-------------------------------------------------------------
ExistingConnection  set transaction isolation level read committed
AuditLogin          set transaction isolation level read committed

READ COMMITTED is always in these events. So it is not about my code, because IsolationLevel.Serializable is set above.

Attempt #2:

For the transaction has been started and not committed yet, it is possible to take SPID and manually select real isolation level from dm_exec_sessions view:

SELECT transaction_isolation_level
FROM sys.dm_exec_sessions
WHERE session_id = @Tran_SPID

This is very undesirable way.

Is it possible to record isolation level for any EF-generated transaction/session in profiler directly? Maybe I just use wrong tool?

P.S. Entity Framework 6.1.3 and MS SQL Server 2012 on board.

1
9
7/21/2015 11:20:26 AM

Popular Answer

You picked the wrong tools because with Entity Framework Profiler you can easily check the isolation level (and lots of information about EF behaviour).

This is my transaction sample :

begin transaction with isolation level: ReadCommitted

EF Profiler

More info : https://hibernatingrhinos.com/products/efprof/learn

0
12/7/2019 12:09:36 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow