How to totally lock a row in Entity Framework

前端 未结 3 452
猫巷女王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 12:51

    you can set the isolationlevel on the transaction in Entity framework to ensure no one else can change it:

    YourDataContext.Database.BeginTransaction(IsolationLevel.RepeatableRead)
    

    RepeatableRead Summary: Locks are placed on all data that is used in a query, preventing other users from updating the data. Prevents non-repeatable reads but phantom rows are still possible.

提交回复
热议问题