fix: eliminate multi-save in batch Add and DeleteAsync(TEntityId)

- Add(TEntity[]) now passes save:false in the loop and calls SaveChanges once at the end
- DeleteAsync(TEntityId) now calls DoRemove directly instead of Delete(TEntityId) to avoid the double-save from the sync overload chain

Ref: #IT-631
This commit is contained in:
Anatolii Grynchuk
2026-05-06 12:43:27 +03:00
parent 4020981eec
commit 93461fd35e
+11 -2
View File
@@ -40,7 +40,12 @@ public abstract class BaseEfRepository<TDbContext, TEntity, TEntityId> :
{ {
foreach (TEntity entity in entities) foreach (TEntity entity in entities)
{ {
Add(entity, save); Add(entity, save: false);
}
if (save)
{
DbContext.SaveChanges();
} }
} }
@@ -84,7 +89,11 @@ public abstract class BaseEfRepository<TDbContext, TEntity, TEntityId> :
public async Task DeleteAsync(TEntityId id) public async Task DeleteAsync(TEntityId id)
{ {
Delete(id); TEntity? entity = GetById(id);
if (entity != null)
{
DoRemove(entity);
}
await DbContext.SaveChangesAsync(); await DbContext.SaveChangesAsync();
} }