Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4016778
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:46:54+00:00 2026-05-20T09:46:54+00:00

I am evaluating EF for my next new apps. How can I globally change

  • 0

I am evaluating EF for my next new apps.

How can I globally change the IsolationLevel of all EF transactions in an application?
Ex: Suppose I want to use “Read Committed Snapshot”.

While it is OK to specify the IsolationLevel when I explicitely need a TransactionScope anyway (see code below) it would be ugly having to encapsulate every EF save operation in a TransactionScope.

 'OK
    Using tsc As New TransactionScope(TransactionScopeOption.RequiresNew, TransactionOption.ReadCommitted)
        UpdateShoppingCart
        EnqueueNewOrder
        SendConfirmationEmail
        tsc.Complete
    End Using

    'Is this really the only way to avoid Serializable?
    Using tsc As New TransactionScope(TransactionScopeOption.RequiresNew, TransactionOption.ReadCommitted)
      _ctx.SaveChanges()
      tsc.Complete
    End Using

    Class TransactionOption
        Public Shared ReadOnly ReadCommitted As New TransactionOptions() With {
            .IsolationLevel = IsolationLevel.ReadCommitted,
            .Timeout = TransactionManager.DefaultTimeout
            }
    End Class

I assume mixing IsolationLevles is not a good idea. Am I wrong with that?

With Serializable and SQL Server (in contrast to Oracle) inserting a simple innocent looking read may cause a conversion lock deadlock.

From the EF FAQ:
“It is recommended that you use READ COMMITTED transactions, and use READ COMMITTED SNAPSHOT ISOLATION if you need to have readers not block writers and writers not block readers.”

I do not understand why EF defaults to Serializable and makes it so difficult to change the default isolation level – with SQL Server (in contrast to Oracle’s multi-versioning) defaulting to a pessimistic concurrency model. A configuration option should be very easy to implement – or am I missing something here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:46:55+00:00Added an answer on May 20, 2026 at 9:46 am

    I’m almost sure that default EF transaction isolation level is based on used database provider. SaveChanges executes this code:

        ... 
        try
        {
            this.EnsureConnection();
            flag = true;
            Transaction current = Transaction.Current;
            bool flag2 = false;
            if (connection.CurrentTransaction == null)
            {
                flag2 = null == this._lastTransaction;
            }
            using (DbTransaction transaction = null)
            {
                if (flag2)
                {
                    transaction = connection.BeginTransaction();
                }
                objectStateEntriesCount = this._adapter.Update(this.ObjectStateManager);
                if (transaction != null)
                {
                    transaction.Commit();
                }
            }
        }
        ...
    

    As you can see BeginTransaction is called without IsolationLevel specified. Under the hood it creates provider specific transaction with IsolationLevel.Unspecified. Unspecified isolation level should result in default isolation level for database server / driver. In SQL Server default isolation level is READ COMMITED so I expect it should use it but I haven’t tested it yet.

    If you want to globally change isolation level you can override SaveChanges in your class derived from ObjectContext and wrap base.SaveChanges() in custom TransactionScope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently evaluating the technologies we want to use for our next project. It
I'm evaluating a database for my next project. I want to store all the
I'm currently evaluating the use of ADO.NET for a C++ application that currently uses
I'm currently evaluating the MSF for CMMI process template under TFS for use on
I'm evaluating Terracotta to help me scale up an application which is currently RAM-bounded.
My company has been evaluating Spring MVC to determine if we should use it
I have been building a new application using my current understanding of domain driven
I'm evaluating SproutCore for possible use as a front end with an existing Grails
I'm evaluating Flex 4.5 for use as a mobile development platform. The demo version
I'm evaluating the use of CRM 2011 to replace one of our existing LOB

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.