dotnet / ef6

This is the codebase for Entity Framework 6 (previously maintained at https://entityframework.codeplex.com). Entity Framework Core is maintained at https://github.com/dotnet/efcore.

Home Page:https://docs.microsoft.com/ef/ef6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EF Framework - Temporal tables Race conditions last update not stored

vsfeedback opened this issue · comments

This issue has been moved from a ticket on Developer Community.


I am developing an ASP.NET webAPI application using .NET Framework 4.8. In the database, I am using the Temporal tables features in a SQL Server 2017 to track the changes of the stored records. For data access, I am using Entity Framework as an ORM. This seems to work fine, however, if I update a record, and directly afterwards delete the record using the code below:

_var recordForDelete = await _dbContext.record.FirstOrDefaultAsync(x => x.ID == id);

recordForDelete.LastModifiedBy = (int)SystemActions.System;

await _dbContext.SaveChangesAsync();

_dbContext.record.Remove(recordForDelete);

await dbContext.SaveChangesAsync();

The last update performed is not captured in the system versioning tables, the record is directly marked as deleted (by setting the system end time) without the last update. It seems to be some sort of race condition, as adding a Task Delay between the two calls to _dbContext.SaveChangesAsync() solves the issue. I also tried to change to _dbContext.SaveChanges() but this didn't solve the problem. Any recommendations on how to solve this issue.?


Original Comments

Feedback Bot on 9/28/2022, 08:40 AM:

(private comment, text removed)

Feedback Bot on 1/5/2023, 06:31 AM:

(private comment, text removed)


Original Solutions

(no solutions)

This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.