performance: multiple attach on Update with EfCore

pull/17998/head
Huang Tao 2 years ago
parent 5a70b96f74
commit cde7446d32
No known key found for this signature in database
GPG Key ID: F505410DF0AF9847

@ -161,16 +161,17 @@ public class EfCoreRepository<TDbContext, TEntity> : RepositoryBase<TEntity>, IE
{
var dbContext = await GetDbContextAsync();
dbContext.Attach(entity);
var updatedEntity = dbContext.Update(entity).Entity;
if (dbContext.Set<TEntity>().Local.All(e => e != entity))
{
dbContext.Update(entity);
}
if (autoSave)
{
await dbContext.SaveChangesAsync(GetCancellationToken(cancellationToken));
}
return updatedEntity;
return entity;
}
public async override Task UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)

Loading…
Cancel
Save