I'm using ABP 8.2.2
We want to use a customer bulk operation provider, but we've noticed that updates to our database seem to happen twice in some cases.
In one specific scenario in a Domain manager method, we are modifying a value on a domain object we can call Foo here and then adding a child object to a collection on Foo.
Previously we were making a call to our custom bulk operation library instead of calling UpdateMany on our ABP repository. We noticed the unexpected behavior of two updates happening here.
So I decided to comment out the call to our our bulk operation library and have no update call at all. In this case, the update still happens.
We realized this is probably because of the default behavior of the uow autoSaving. I've made multiple attempts to turn off this autoSave, all without success so far. I've attempted to disable change tracking on both the Foo repository and even on the Domain Manager and still the update happens.
What's the best way to handle this situation? We want the update to happen through our bulk operation library and only there.
Thanks!
1 Answer(s)
-
0
Hi,
In Entity Framework doesn't define any kind of bulk operations and it uses
AddRangeAsync()
method. If the database provider and EF adapter package supports, it updates database once but it's not guaranteed. It depends on your provider and provider package.You can provide a method for bulk operations by implementing
IEfCoreBulkOperationProvider
on your own and use such libraries like [EntityFramework-Plus(https://github.com/zzzprojects/EntityFramework-Plus) inside this provider implementation:[Dependency(ReplaceServices = true)] [ExposeServices(typeof(IEfCoreBulkOperationProvider))] public class MyProjectNameBulkOperationProvider : IEfCoreBulkOperationProvider, ITransientDependency { public async Task DeleteManyAsync<TDbContext, TEntity>(IEfCoreRepository<TEntity> repository, IEnumerable<TEntity> entities, bool autoSave, CancellationToken cancellationToken) where TDbContext : IEfCoreDbContext where TEntity : class, IEntity { // Your custom bulk delete logic here... } public async Task InsertManyAsync<TDbContext, TEntity>(IEfCoreRepository<TEntity> repository, IEnumerable<TEntity> entities, bool autoSave, CancellationToken cancellationToken) where TDbContext : IEfCoreDbContext where TEntity : class, IEntity { // Your custom bulk insert logic here... } public async Task UpdateManyAsync<TDbContext, TEntity>(IEfCoreRepository<TEntity> repository, IEnumerable<TEntity> entities, bool autoSave, CancellationToken cancellationToken) where TDbContext : IEfCoreDbContext where TEntity : class, IEntity { // Your custom bulk update logic here... } }