如何实现具有并发和事务支持的 Linq-to-Sql 计数器缓存?
我有一个场景,我想要一个问题对象,并且用户可以同时将答案对象添加到问题对象中。 问题对象需要维护答案计数。
如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用附加到问题的答案对象的数量更新答案计数。 然后您不必担心并发性,因为它只会计算存在的答案数量(在任何给定时刻)。
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).