Concurrency management in entity structure

I am trying to convert my code from Linq-to-SQL to Entity Framework 6. I noticed that the concurrency control options in Entity Framework are quite limited.

Question : which is equivalent to ConflictMode.ContinueOnConflict, and ConflictMode.FailOnFirstConflictin Entity Framework? How can I just try to save all changes at once in db and collect all conflicts later? As far as I know, there is no direct way to EF, or am I missing something?

In particular, how to change this code to the EF6 style?

try
{
    storage.Accounts.InsertAllOnSubmit(newAccountsList);
    storage.SubmitChanges(ConflictMode.ContinueOnConflict);
}
catch (ChangeConflictException)
{
    var failedItems = storage.ChangeConflicts;
    foreach (var failedItem in failedItems)
    {
        failedItem.Resolve(RefreshMode.KeepCurrentValues);
    }
}
catch (KeyViolationException)
{
    // Here I'm doing nothing
}

storage.SubmitChanges(ConflictMode.FailOnFirstConflict);

Any help would be greatly appreciated. It is impossible to understand this.

+4
source share

Source: https://habr.com/ru/post/1527666/


All Articles