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

时间:2020-12-07 14:29:08

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?

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

1 个解决方案

#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).

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

#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).

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