operation.AllowConcurrency does not exist in EF Core Extensions
Description
I have a problem with implementing ConcurrencyException as described on following page: https://entityframework-extensions.net/concurrency
the operation.AllowConcurrency does not exist in EF Core Extensions I'm using Z.EntityFramework.Extensions.EFCore 6.15.1
How to handle Concurrency Exceptions? Any suggestions?
public void BulkUpdate_StoreWins<T>(CurrentContext ctx, List<T> list) where T : class { try { ctx.BulkUpdate(list); } catch (DbBulkOperationConcurrencyException ex) { // FORCE update store entities ctx.BulkUpdate(list, operation => operation.AllowConcurrency = false); } }
Further technical details
- EF version: Microsoft.EntityFrameworkCore.SqlServer 6.0.9
- EF Extensions version: Z.EntityFramework.Extensions.EFCore 6.15.1
- Database Provider: SQL Server
Hello @KamilBarbachowski ,
Indeed this page and the option were done for EF6 years ago and not for EF Core 6.
We will look at it.
Best Regards,
Jon
Indeed I've found the concurrency detection logic to be extremely bad in the EF Core version of the extensions.
In fact, the only place I got it to work is during an Update (not Delete), and then only when doing
db.Set<SomeEntity>().UpdateRange(...);
db.BulkSaveChangesAsync(...);
Any other bulk operation (e.g. one of the immediate BulkUpdate, BulkDelete, operations...) will happily overwrite data without warning. Same if you do db.RemoveRange() and then db.BulkSaveChanges().
Calling the normal db.SaveChanges() or SaveChangesAsync() will throw DbUpdateConcurrencyException as expected so this is all in the extensions.
Hello @KamilBarbachowski , @isak1080 ,
With the latest version, we updated how we handle concurrency. See the following documentation: https://entityframework-extensions.net/concurrency
You will find an example of how to manage concurrency with BulkSaveChanges.
Due to backward compatibility, you will need to enable concurrency for operations such as BulkDelete, BulkUpdate, and BulkMerge with the following options: EnableConcurrencyForBulkOperation = true . We cannot enable it by default as we might break many codes currently in production.
Let me know if you have any questions about it.
Best Regards,
Jon