UpdateModel() 导致行无法更新

发布于 2024-08-24 02:46:46 字数 395 浏览 8 评论 0原文

我在使用 UpdateModel(theModelToUpdate) 时遇到问题,导致并发问题。

基本上发生的情况是,数据库中有一行包含该行所需的大部分但不是全部信息。其余所需信息为 NULL。然后,用户(使用列表框)将信息添加到该行,并创建新行(为列表框中的每个项目发送一个 ajax 命令。因此,由于用于获取项目)。

在我的控制器中,我首先检查用户要更新的列是否为 NULL。如果是,我使用 UpdateModel 来更新该行。如果它们不为空(意味着该行已完成),那么我将使用剩余的列表框项目创建新行。

调试时,我注意到由于控制器被调用得如此之快,因此 UpdateModel 并没有像我计划的那样立即被调用。因此,列表框中的几个项目被跳过,并且我收到一条错误消息,指出该行无法更新。

我该如何解决这个问题?

I'm having a problem using UpdateModel(theModelToUpdate) causing concurrency issues.

Basically whats happening is, there is a row in the database that contains most but not all the information needed for that row. The rest of the needed information is NULL. The user (using a listbox) would then add information to this row, as well as creating new rows (An ajax command is sent for every item in the listbox. So the controller is being called very fast because of the loop used to get the items).

In my controller I first check to see if the columns the user will be updating are NULL. If they are, I use UpdateModel to update the row. If they are not null (meaning the row is complete ) then I create new rows with the remaining listbox items.

When debugging, I notice that since the controller is called so quickly, the UpdateModel isn't called right away like I had planned. Several items from the listbox get skipped because of this and I get an error saying the row cannot be updated.

How can I solve this?

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

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

发布评论

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

评论(2

ζ澈沫 2024-08-31 02:46:46

不确定我是否正确:When is the controller invoked using AJAX?您说这种情况发生得非常快,所以我假设您在提交时多次调用控制器,而不是每次用户实际添加行时。在“非常快”下,我理解每秒多个操作。

好吧,这一次我认为如果您只是向行添加一个条目,那么您不应该使用 UpdateModel - 您可以手动执行此操作。

其次,快速连续地对同一项目调用控制器确实可能会导致数据库上的并发问题,因为它必须在某处获取锁。但是,我认为这取决于您的数据库抽象、数据库类型和您使用的锁定机制。

我建议您编写一个小型控制器操作,仅以交互方式添加一个条目,即每次用户实际执行某操作时。这应该可以避免并发问题。

Not sure I got this right: When is the controller invoked using AJAX? You say this happens very fast, so I assume you invoke the controller multiple times on submit, rather than every time the user actually adds a row. Under "very fast" I understand multiple operations per second.

Well, for once I think you shouldn't use UpdateModel if you merely add an entry to a row - you could do this manually.

Second, invoking the controller on the same item in fast succession might indeed lead to concurrency issues on the database because it has to acquire a lock somewhere. However, I think this will depend on your database abstraction, the database type and the locking mechanism you use.

I'd suggest you write a small controller action that only adds a single entry interactively, i.e every time the user actually does something. This should keep you from concurrency issues.

焚却相思 2024-08-31 02:46:46

我通过不使用 UpdateModel 更新行解决了该问题。相反,我插入行,然后返回并删除缺少信息的行。可能不是最好的解决方案,但它解决了我的问题。

I resolved the issue by not using UpdateModel to update the row. Instead I Insert the rows, then go back and delete the row with the missing information. Probably not the best solution, but it fixed my problem.

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