Handle concurrency problem by Entity Framework
2013-09-11 20:56
369 查看
Database concurrency
A concurrency conflict occurs when multiple users try to change the same data simultaneously. For example, if user one and user two load the same product from database, the user who clicks submit
button last will be the one who wins, and the user's data will override the first user's data without any warning being given to either user.
How to handle the concurrency problem?
A. Pessimistic concurrency. This approach uses the database row lock. Obviously, this approach has performance problem.
B. Optimistic concurrency. This approach verifies that the data to be updated has not been modified after retrieving. Entity framework supports this approach.
With entity framework, you need to define a timestamp column in the database table, then you need to put a [Timestamp] attribute for the column in the entity model. Then when you try to update a table,
entity framework will check if the data has been changed by comparing the time stamp filed, if it has been changed , then entity framework will throw a exception of OptimisticConcurrencyException.
But Timestamp data type of SQL Server will be removed in the future, one new equivalent data type rowversion should be used.
A concurrency conflict occurs when multiple users try to change the same data simultaneously. For example, if user one and user two load the same product from database, the user who clicks submit
button last will be the one who wins, and the user's data will override the first user's data without any warning being given to either user.
How to handle the concurrency problem?
A. Pessimistic concurrency. This approach uses the database row lock. Obviously, this approach has performance problem.
B. Optimistic concurrency. This approach verifies that the data to be updated has not been modified after retrieving. Entity framework supports this approach.
With entity framework, you need to define a timestamp column in the database table, then you need to put a [Timestamp] attribute for the column in the entity model. Then when you try to update a table,
entity framework will check if the data has been changed by comparing the time stamp filed, if it has been changed , then entity framework will throw a exception of OptimisticConcurrencyException.
But Timestamp data type of SQL Server will be removed in the future, one new equivalent data type rowversion should be used.
相关文章推荐
- “System.Data.Entity.Infrastructure.DbUpdateConcurrencyException”类型的异常在 EntityFramework.dll 中发生,但未在用户
- 转载:ADO.NET Entity Framework By WXwinter
- Entity Framework Tutorial Basics(28):Concurrency
- EntityFramework CodeFirst 4.3 step by step (2)
- EntityFramework CodeFirst 4.3 step by step (3)
- Entity Framework Code-First(9.3):DataAnnotations - ConcurrencyCheck Attribute
- Using LINQ Group By and String.Join() / Aggregate() in Entity Framework 3.5
- EntityFramework CodeFirst 4.3 step by step (4)
- ADO.NET Entity Framework step by step
- Lerning Entity Framework 6 ------ Handling concurrency With SQL Server Database
- Entity Framework Unit Testing problem and solution(转)
- shining cento in book reading: handle out of memory problem for new operator -by register a global SetNewHandler
- EntityFramework CodeFirst 4.3 step by step (1)
- Managing DbContext the right way with Entity Framework 6: an in-depth guide by mehdime
- ADO.NET Entity Framework学习系列-----(1)Entity Framework出场!
- Entity Framework Core 2.1 Preview 1 新增功能简介
- Entity Framework Code First使用者的福音 --- EF Power Tool使用记之一(转)
- <Entity Framework> - 直接执行数据库命令
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第一章:创建基本的MVC Web站点
- 给vs2010中内置sqlserver2008添加了一个添加了一个管理界面后ADO.NET FrameWork Entity连接不上sqlserver2008