0

Due to performance in our system (deadlocks, db reads are locked when db writes are in progress, etc) we want to try out snapshop isolation. I have read about snapshot isolation level, here. We use Entity Framework

I have set Snapshop isolation on the db and want to configure our web api apps to use this isolation for both reads and writes. How can I do this? I have read that this can be done in web.config but cannot find how..

Richard
  • 106,783
  • 21
  • 203
  • 265
JohanLarsson
  • 475
  • 1
  • 8
  • 23
  • How are you talking to the DB: ADO.NET directly, or via some ORM? (In the latter case: which one?) – Richard Sep 23 '15 at 09:41

1 Answers1

1

According to the Entity Framework documentation, you need to use a transaction to set the isolation level:

using (var tx = myContext.Database.BeginTransaction(IsolationLevel.Snapshot)) {

   // Perform operations on the context...

   await myContext.SaveAsync();
   tx.Commit();
}

See also this answer for details on the defaults: essentially EF uses whatever the database has as its default transaction isolation level via IsolationLevel.Unspecified.

Community
  • 1
  • 1
Richard
  • 106,783
  • 21
  • 203
  • 265
  • ok so If I have set snapshop isolation level on the db then that is what EF will use? If so does that also apply when using TransactionScope-class in .net – JohanLarsson Sep 23 '15 at 10:06
  • @JohanLarsson See the linked answer for the first part. You need to RTFM for the second (but I would guess yes). – Richard Sep 23 '15 at 10:08