Tip: LinqDataSource - Timestamp应是必备数据列

最近喜欢上了LinqDataSource,因为不必自己写数据访问的代码,而且还内置了并发控制,避免了"dirty read /write"问题。什么是并发控制:
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,带来性能问题
2. 敏感数据存储在ViewState中可能带来的安全问题
如果数据源支持Timestamp数据类型,免去了基于所有数据列的old value与new value的比较,可以很好的解决以上两个问题:
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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值