How to totally lock a row in Entity Framework

前端 未结 3 483
猫巷女王i
猫巷女王i 2021-02-05 12:10

I am working with a situation where we are dealing with money transactions.

For example, I have a table of users wallets, with their balance in that row.



        
3条回答
  •  庸人自扰
    2021-02-05 13:10

    The whole point of a transactional database is that the consumer of the data determines how isolated their view of the data should be.

    Irrespective of whether your transaction is serialized someone else can perform a dirty read on the same data that you just changed, but did not commit.

    You should firstly concern yourself with the integrity of your view and then only accept a degredation of the quality of that view to improve system performance where you are sure it is required.

    Wrap everthing in a TransactionScope with Serialized isolation level and you personally cannot really go wrong. Only drop the isolation level when you see it is genuinely required (i.e. when getting things wrong sometimes is OK).

    Someone asks about this here: SQL Server: preventing dirty reads in a stored procedure

提交回复
热议问题