Gentle.NET笔记(五)-同步控制

Gentle support row-level concurrency control, that is, it provides a means of ensuring data integrity when multiple processes may be accessing the same data (typical for web applications).


Note:Gentle支持低级的同步控制,提供了在多线程环境中能够确保所有的线程访问相同的数据。

To add concurrency control to your solution you must decorate an integer field (member or property) with the Concurrency attribute (alongside the TableColumn attribute). This designates the field as a control column in which Gentle will store a revision number for the given row.

Note:加入同步控制,需要用Concurrency特性对一个数字型字段进行修饰(成员或属性)

The revision counter is used as an additional criteria in the WHERE clause of any single-row update SQL statement against the table. Additionally, it is incremented by 1 on every update (both in-memory and in the database). This ensures that old data cannot be used to update a row.When you try to update a row using outdated data, Gentle throws a GentleException whose Error property will be set to Error.RecordChanged. You should wrap all updates to check for this specific error in your code. If you use the Persistent as base class, this can be done by creating your own base class and overriding the Update method.

You can use the Refresh method to recover from concurrency errors (available on Persistent, PersistenceBroker and Broker). This will update the current object with the database values, and potentially allow you to re-execute the update.
Note: The revision counter is not checked when deleting one or more rows

Note:每次使用Update时,都会使版本字段的值增1(内存与数据库中同时增加),这可以确保老的数据不会在被更新后再次使用。当使用一个过期的数据时,Gentle会抛出一个GentleException异常,通过捕获这个特定异常,就可以知道数据版本是否发生了冲突。同时,可以使用Refresh方法对数据进行刷新,从而解决同步错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值