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.
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.
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.
To check the isolation level(s) present in the statement, the simplest way is to look at the T-SQL itself and see if any hints are present. If not, it is operating at the isolation level of the connection.
We can set Isolation Level using the ExecuteStoreCommand method of the context. It would affect generated LINQ to Entity queries. DBContext or Object context also supports explicitly setting the transaction on the context. Using transaction scope we can set transaction Isolation Level for current transaction.
The isolation level of the transactional support is default to READ UNCOMMITTED. You can change it to READ COMMITTED SNAPSHOT ISOLATION by turning ON the READ_COMMITTED_SNAPSHOT database option for a user database when connected to the master database.
InnoDB offers all four transaction isolation levels described by the SQL:1992 standard: READ UNCOMMITTED , READ COMMITTED , REPEATABLE READ , and SERIALIZABLE .
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
More info : https://hibernatingrhinos.com/products/efprof/learn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With