如何实现具有并发和事务支持的 Linq-to-Sql 计数器缓存?

发布于 2024-07-26 23:31:32 字数 150 浏览 3 评论 0原文

我有一个场景,我想要一个问题对象,并且用户可以同时将答案对象添加到问题对象中。 问题对象需要维护答案计数。

如何在 Linq2Sql 中实现以事务方式保存用户提交给问题的答案对象并更新问题对象的递增答案计数,并在尝试更新问题对象的答案计数时处理任何并发冲突?

I have a scenario where I want to have a question object and users can concurrently add answer objects to the question object.
The question object needs to maintain the answer count.

How can I do an implementation in Linq2Sql that transactionaly saves the answer object that the user submitted to the question and updates the incremented answer count of the question object and also handles any concurrency violations when trying to update the answer count of the question object?

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

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

发布评论

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

评论(1

旧瑾黎汐 2024-08-02 23:31:32

使用附加到问题的答案对象的数量更新答案计数。 然后您不必担心并发性,因为它只会计算存在的答案数量(在任何给定时刻)。

Update the Answer Count with the count of the number of answer objects attached to the question. Then you won't have to worry about concurrency because it will just count the number of answers that are there (at any given moment).

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