locked
my queries and getting serialized isolation RRS feed

  • Question

  • User2102072086 posted

    hi,

    i am using entitiy framwok and transactionscop with required transaction parameter.

    all my quires are taking serialized isolation , please suggest where i have gone worng and please suggest how to change to read commited.

    yours sincerley

    Friday, August 5, 2016 2:16 PM

Answers

  • User-2057865890 posted

    Hi rajemessage,

    Entity Framework automatically wraps all the queries made by the DbContext.SaveChanges() method in a single explicit database transaction, therefore ensuring that all the changes applied to the context are either committed or rolled-back in full.

    It will use whatever default transaction isolation level the database engine has been configured to use (READ COMMITTED by default for SQL Server).

    You can override EF's default behaviour and control the database transaction scope and isolation level.

    using (var context = new MyDbContext(ConnectionString))  
    {
        using (var transaction = context.BeginTransaction(IsolationLevel.RepeatableRead))
        {
            [...]
            context.SaveChanges();
            transaction.Commit();
        }
    }

    reference:

    http://stackoverflow.com/a/12795274

    http://mehdi.me/ambient-dbcontext-in-ef6/

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 16, 2016 3:11 AM

All replies

  • User-2057865890 posted

    Hi rajemessage,

    The behavior of READ COMMITTED depends on the setting of the READ_COMMITTED_SNAPSHOT database option:

    If READ_COMMITTED_SNAPSHOT is set to OFF (the default), the Database Engine uses shared locks to prevent other transactions from modifying rows while the current transaction is running a read operation. The shared locks also block the statement from reading rows modified by other transactions until the other transaction is completed. The shared lock type determines when it will be released. Row locks are released before the next row is processed. Page locks are released when the next page is read, and table locks are released when the statement finishes.

    reference:

    SET TRANSACTION ISOLATION LEVEL (Transact-SQL)

    How do I set the transaction isolation level when connecting to a SQL Server database

    Best Regards,

    Chris

    Saturday, August 6, 2016 7:00 AM
  • User2102072086 posted

    i asked some thing else , it was about serialized isolation level, i wanted to know is entitiy frame work or transaction scopes are picking up automatically

    or by default ( serialized ).

    if yes then pls tel me the good way to making it read commited.

    Saturday, August 6, 2016 10:25 AM
  • User-2057865890 posted

    Hi rajemessage,

    Entity Framework automatically wraps all the queries made by the DbContext.SaveChanges() method in a single explicit database transaction, therefore ensuring that all the changes applied to the context are either committed or rolled-back in full.

    It will use whatever default transaction isolation level the database engine has been configured to use (READ COMMITTED by default for SQL Server).

    You can override EF's default behaviour and control the database transaction scope and isolation level.

    using (var context = new MyDbContext(ConnectionString))  
    {
        using (var transaction = context.BeginTransaction(IsolationLevel.RepeatableRead))
        {
            [...]
            context.SaveChanges();
            transaction.Commit();
        }
    }

    reference:

    http://stackoverflow.com/a/12795274

    http://mehdi.me/ambient-dbcontext-in-ef6/

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 16, 2016 3:11 AM