最近喜欢上了LinqDataSource,因为不必自己写数据访问的代码,而且还内置了并发控制,避免了"dirty read /write"问题。什么是并发控制:
看一下msdn的文档,其默认的并发控制机制依赖于数据列old value与new value的比较:
When you enable users to update or delete data, you might want to make sure that the data in the data source has not been changed by another process before you continue with the update or delete. If you do not check whether the values have changed, you can unintentionally overwrite values set by another process and leave the data in an inconsistent state.
看一下msdn的文档,其默认的并发控制机制依赖于数据列old value与new value的比较:
The LinqDataSource control enables you to determine whether the data has changed. The control stores the original data values in view state in the Web page. When the Web page is posted back, the page contains both the original values and any updated values. The LinqDataSource control uses LINQ to SQL to compare the original values with the values currently in the data source. If the values are the same, the data has not changed, and LINQ to SQL updates or deletes the data. If the data has changed, LINQ to SQL raises an exception.这一机制的副作用是:
http://msdn.microsoft.com/en-us/library/bb547113.aspx
1. 增大了页面的ViewState,带来性能问题如果数据源支持Timestamp数据类型,免去了基于所有数据列的old value与new value的比较,可以很好的解决以上两个问题:
2. 敏感数据存储在ViewState中可能带来的安全问题
A timestamp column is automatically updated by SQL Server every time that the record is modified. For more information, see Timestamp (Transact-SQL). In the entity class, a timestamp column is marked by having the IsVersion property set to true.
http://msdn.microsoft.com/en-us/library/bb470449.aspx