I am trying to find working and optimal solution for the following situation:
- I have WebService in the cloud written on c#;
- Endpoint of this service can be called in a random time with random frequency;
- During handling of request we call method where we have read \ write operations on the table in our DB (I have simplified flow):
- we read data from table
- apply some validation rules
- and according to specific rules update some fields and write data back to the table
- commit transaction
The real problem is when we have 2 or 3 simultaneous request for one user - we easily get to the situation when we read invalid data from the table, because previous operation didn't save results (commit transaction) yet.
- I've tried to setup isolation level, but it is reason for deadlock.
- Usage of Upsert operation on DB level requires moving logic to stored procedure - it is not desirable.
So the question: what is the best way to synchronize work with DB correctly? Thank you for any suggestions.
Tools: Entity Framework 6.0, Azure SQL, Azure