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:
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user