RIA 真的存在并发问题吗?

发布于 2024-11-14 12:46:53 字数 566 浏览 2 评论 0原文

在我提到的 Pluralsight RIA 服务的一个视频中,他们有一个这样的更新代码:

public void UpdateProspect(Prospect currentProspect)
{
    currentProspect.LastUpdate = DateTime.Now;
    ObjectContext.Prospects.AttachAsModified(currentProspect, ChangeSet.GetOriginal(currentProspect));
}

我的第一个问题是这个更新将如何导致问题?为了显示问题,他启动了两个 Silverlight 客户端,然后从第一个客户端更新了该项目,并且更新得很好。然后他转到第二个客户端并进行更新,然后抛出错误。

为什么 RIA 会抛出错误?和第一次更新有什么关系?我认为这确实是有问题的,我们需要再次编写一些特殊的代码来解决实体冲突,然后再次将批次提交到服务器。这合适吗?

他还将 ConcurrencyMode 设置为固定。我的第二个问题是什么时候将 ConcurrencyMode 设置为固定?默认情况下,模式设置为“无”。

In one of the videos of RIA services of Pluralsight I was referring, they had an update code like this:

public void UpdateProspect(Prospect currentProspect)
{
    currentProspect.LastUpdate = DateTime.Now;
    ObjectContext.Prospects.AttachAsModified(currentProspect, ChangeSet.GetOriginal(currentProspect));
}

My first question is how will this update cause problems? To show the problems he starts two Silverlight clients, then from first client he updates the item and it updates nicely. Then he goes to the second client and makes an update and it throws an error.

Why is RIA throwing errors? What has it got to do with the first update? This is really buggy I think and we need to again write some special code to resolve the EntityConflict and then again submit the batch to the server. Is this appropriate?

He also set the ConcurrencyMode to Fixed. My second question is when would you set the ConcurrencyMode to Fixed? By default, the mode is set to None.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终遇你 2024-11-21 12:46:53

这是因为陈旧读取引起的竞争条件。考虑以下情况:

  1. 两个客户端获取 Prospect 的副本 - 让我们称之为版本 1
  2. A 修改 LastUpdate 属性,该对象现在是版本 2
  3. A 保存 Prospect
  4. B 修改 LastUpdate 属性。对于客户 B 来说,版本现在是版本 2,但是客户 B 的版本 2 与客户 A 的不同,
  5. B 保存了前景 - 这将覆盖客户 A 的更改!

这里的问题是 B 无法知道 A 进行了任何更改。抛出异常是为了防止竞争条件意外删除数据。

解决方案是捕获此异常并报告 Prospect 在您编辑时已更改,然后重新加载它。

您可以在此处找到有关使用 ConcurrencyMode=fixed 的更多信息< /a>.

This is because of a race condition caused by a Stale Read. Consider the following:

  1. Two clients get a copy of the Prospect - lets call it version 1
  2. A modifies the LastUpdate property, the object is now version 2
  3. A saves the Prospect
  4. B modifies the LastUpdate property. To Client B, the version is now version 2 but Client B's version 2 is different from Client A's
  5. B saves the Prospect - this would overwrite Client A's changes!

The problem here is that B can't know that A has made any changes. The Exception is thrown to prevent the race condition from accidentally deleting data.

The solution is to catch this exception and report that the Prospect was changed while you were editing it, and then reload it.

You can find more information about using ConcurrencyMode=fixed here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文