数据集乐观并发
我需要在数据集 C# 客户端中执行哪些操作来处理乐观并发?
这篇文章并未涉及很多内容除了使用时间戳之外的详细信息
What would I need to do in my dataset C# client for handling optimistic concurrency?
This article does not go into many details except from use a timestamp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这并不正确,本文仅提到时间戳(前半部分或文章中的用例),并且提供了有关第二个乐观锁实现的更多详细信息 -
。神奇的是通过以下语句执行的:
所以您只需听
RowUpdated 事件,如果
RecordsAffected
为零,则发生了不好的事情。基于时间戳的实现也非常明显。您将拥有一个日期时间和数据集:
要更新,您将有两种方法 - 显式,当您在尝试保存任何内容之前检查时间戳时:
或者隐式,就像文章中描述的第二种方式 - 尝试使用时间戳进行更新条件:
如果更新了零行,那么您将了解并发异常并相应报告。
That's not really correct, the article just mentions timestamps (the use case in the first half or the article), and alternatively provides more details on the second optimistic lock implementation -
The magic is performed by the following statement:
So you'd just listen to
RowUpdated
event, and ifRecordsAffected
is zero then something bad happened.Timestamp-based implementation is pretty obvious as well. You'll have a datetime along with your dataset:
For updating you'll have two ways - explicit, when you check timestamps even before attempting to save anything:
Or implicit, like the second way described in the article - try update using timestamp as a condition:
and if zero rows are updated then you'll know about concurrency exception and report correspondingly.
假设你自己处理这一切。
如果您最初从数据库检索的时间戳小于当前在对象上保留的时间戳,则其他人已经保留了数据,并且您不应该允许当前用户保留数据,或者至少提示他们可能会覆盖更改。
如果没有更详细的问题,我真的不知道还能说什么。
Assuming your handling this all yourself.
If the timestamp you retrieved from the DB originally is less then the timestamp currently persisted on the object, then someone else has persisted data and you should not allow the current user to persist, or at least prompt them that they might be overwriting changes.
Without a more detailed question, I don't really know what else to say.
没有什么。它不是数据集的 jkob 来处理这个问题 - 数据集是数据的离线缓存。这是您用来将更改写入数据库的工作,以根据数据集中给出的信息处理乐观并发。
数据集根本不处理数据库交互。
Nothing. it is not the jkob of a data set to handle this - the data set is an offline cache of data. It is the job of whatever you use to write the changes out to the database to handle optimisstic concurrency based on the information given in the dataset.
Datasets do not deal with database interaction at all.