I'm using Entity Framework Core with .NET 6.
I have a function that will auto-generate table primary key of other tables as a id summary and does not consider using Identity
specification in SQL Server to auto-generate table primary key.
The function's processes are as follows:
- Get the max id of table
- Update the newest max id to table
- Return the primary id
And I'm facing the similar question to this question, if my website is using more than one server and there is serveral users create data at once, error might occur (with the conflict of the same ids that returned by function).
I was using T-SQL to fix this problem in Entity Framework with .NET framework 4.6 in the past, the solution just like this in the same article above.
But I'm wondering if there is any better solution now in EF Core? I have searched for Isolationlevel in ef core document, but it seems unable to deal with this situation.
Does anyone have a better solution for this?