0

Suppose that I have a bank account table with columns customer_id, name, address, and balance. Balance is constantly changing because customer is depositing and withdrawing money. How can I chance customer's address without getting an DBConcurrencyException at the same time?

What is the general approach in this situation, it is not possible for two users to change the SAME cell in a table row but it is possible for them to change different cells in same row AND updating the row with new values without problem?

4

2 回答 2

0

我不确定您是否使用 LINQ,但如果您使用了,那么您应该看看它是如何处理并发的。LINQ 使用乐观并发。所以基本上如果一个用户尝试更新一条记录,并且记录在此期间已经更新,那么就会发生并发冲突。

但是,您可以决定 LINQ 表中的哪些属性用于并发检查——在这种情况下,LINQ 不会关心该记录中的值是否已更改。

还有一些方法可以处理异常——你可以在异常周围放置一个 try 块——并编写一些代码来处理不同的场景。

于 2012-08-09T12:57:17.873 回答
0

您应该查看包含详细信息的链接http://blog.sqlauthority.com/2008/08/18/sql-server-detailed-explanation-of-transaction-lock-lock-type-avoid-locks/ 。

于 2012-08-09T10:29:32.950 回答