Concurrency exceptions in Entity Framework

前端 未结 2 1754
-上瘾入骨i
-上瘾入骨i 2021-01-03 21:28

When calling SaveChanges / SaveChangesAsync in Entity Framework (CF, C#), if a change conflict occurs (for example, the values has been updated sin

2条回答
  •  悲哀的现实
    2021-01-03 21:45

    You will get an OptimisticConcurrencyException. Have a look at this.

    Now coming to the diffrence.

    • OptimisticConcurrencyException:thrown when an optimistic concurrency violation occurs(suppose more than one perople are changing to the same result,and this will cause the problem of not being sychronized)
    • DbUpdateConcurrencyException:Exception thrown by DbContext when the expected behavior is that SaveChanges for an entity would result in a database update but in fact no rows in the database were affected. This shows that the database has been concurrently updated and a concurrency token that was expected to match did not actually match. State entries referenced by this exception are not serialized due to security and access to the state entries after serialization will return null.

提交回复
热议问题