Entity Framework and transaction isolation level

前端 未结 1 1902
南旧
南旧 2020-12-02 20:36

I\'m using Entity Framework 4.0. Now I need to restrict access to a table while I\'m reading from it or writing to it. Probably that\'s about transaction isolation level.

相关标签:
1条回答
  • 2020-12-02 21:04

    By default, a Transaction has an IsolationLevel of Serializable. Serializable is the highest level. It requires that the transaction completes before any other transaction is allowed to operate on the data.

    It has the following restrictions:

    • Statements cannot read data that has been modified but not yet committed by other transactions.
    • No other transactions can modify data that has been read by the current transaction until the current transaction completes.
    • Other transactions cannot insert new rows with key values that would fall in the range of keys read by any statements in the current transaction until the current transaction completes.

    This is a great blog post that explains how to use Transactions with the Entity Framework: Entity Framework transaction scope examples

    UPDATE

    In Entity Framework 6 the default IsolationLevel is changed to READ_COMMITTED_SNAPSHOT for databases created using Code First, potentially allowing for more scalability and fewer deadlocks. See the future spec of EF 6

    0 讨论(0)
提交回复
热议问题