Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: 1st query or save does not use isolation level of TransactionScope

$
0
0
I'm seeing an odd issue when using a TransactionScope, in which the first CRUD operation performed never seems to use the scope's isolation level.

For example, assume code like this (for the record, I am well aware that the TransactionScope is not needed here, I am trying to illustrate what I think is a bug):
[TestMethod]
publicvoid TestTransactionIsolation() {

  var options = new TransactionOptions() { IsolationLevel = IsolationLevel.Serializable, Timeout = TimeSpan.FromMinutes(1) };
  using (var transaction = new TransactionScope(TransactionScopeOption.Required, options)) {
    using (var ctx = new NorthwindEntities()) {
      var cust1 = Customer.CreateCustomer(Guid.NewGuid(), "company a");
      ctx.AddToCustomers(cust1);
      ctx.SaveChanges();

      var cust2 = Customer.CreateCustomer(Guid.NewGuid(), "company b");
      ctx.AddToCustomers(cust2);
      ctx.SaveChanges();
    }
     transaction.Complete();
  }
}
A SQL Profiler trace of the above seems to show that the requested isolation level - serializable - is not used with the first save.
Audit Login set transaction isolation level read committed
RPC:Completed   exec sp_executesql N'INSERT [dbo].[Customer] …
Audit Logout    
RPC:Completed   exec sp_reset_connection 
Audit Login set transaction isolation level serializable 
RPC:Completed   exec sp_executesql N'INSERT [dbo].[Customer]…
Audit Logout    
RPC:Completed   exec sp_reset_connection 
Audit Login set transaction isolation level serializable 
Audit Logout    
This behavior seems to be true regardless of whether the first operation is a query or save, and mixing up the TransactionScope/ObjectContext creation order also has no affect.

An error is not thrown, but based on the trace it does seem that the isolation level is initially ignored.

We see this behavior in EF 5, and in EF 6 RC1.

Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>