What is the default transaction isolation level in Entity Framework when I issue “SaveChanges()”? I can not find it anywhere. Shall it be "Serializable"?
.net – the default transaction isolation level in Entity Framework when I issue “SaveChanges()”
ado.netentity-frameworknettransactions
Related Topic
- C# – SqlException from Entity Framework – New transaction is not allowed because there are other threads running in the session
- C# – Fastest Way of Inserting in Entity Framework
- C# – Unable to update the EntitySet – because it has a DefiningQuery and no
element exist - The default transaction isolation level for SQL Server with ADO.NET
- C# – Entity Framework and transaction isolation level
- C# – Entity Framework – retrieve ID before ‘SaveChanges’ inside a transaction
Best Answer
SaveChanges
uses implementation ofDbTransaction
for current store provider. It means that default transaction isolation level is set to default value for the database server. In SQL Server it isREAD COMMITTED
. If you want to change isolation level you can useTransactionScope
. You can also overrideSaveChanges
in your derived context and wrapbase.SaveChanges()
to the scope directly in overriden method.You can further improve this code to allow you passing isolation level to
SaveChanges
etc. Once you start changing isolation levels you should do it consistently. It means you should define isolation level each time you want to run a transaction because isolation level is configured per connection and connections are reused when using connection pooling.Edit: Default transaction level in EF6 has changed to
READ COMMITTED SNAPSHOT