Description
I have handled Optimistic concurrency control in my case and used transactions. I am facing an issue where when an concurrency is occurred and while re-updating the record, creating an invalid row with the old value which I have read before concurrency occurred.
For example: I have three tables as follows.
ProjectCategorySequenceMapper - To maintain Sequence value based on project category
ProjectCategory - To maintain Project Category
Projects - To maintain Project details based on project category
I have used "RowVersion" column in "ProjectCategorySequenceMapper" table for concurrency check.
My goal is to read the sequence value based on project category from "ProjectCategorySequenceMapper" table when I am creating a new project and need to increment the sequence value by one and update in "ProjectCategorySequenceMapper" table.
In this scenario, when I try to create a new project (i.e. expected sequence Id - 3) under category (i.e. CategoryId - 1), once I read the value from database and concurrency occurred and in database sequence Id is updated as 4. I have handled to re-update concurrency and an invalid entry with Project Id 3 is created based on sequence value which is read before concurrency and new expected record created with Project Id 4 when I am using transaction. Without transaction everything works fine as expected whereas an invalid record created when using transaction.
Note:
In Microsoft Azure Sql Database only this invalid record created when using transaction whereas in normal Sql Database this issue not reproduced.
Kindly let me know is this an issue or anything done wrongly in my side.
Further technical details
EF Core version: 3.1.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
IDE: Visual Studio 2019 16.4.4