diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index 607b6a3fa..dbc5b5f8e 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -37,14 +37,19 @@ namespace IRaCIS.Core.Infra.EFCore /// 批量删除,EF跟踪方式(所有查询出来,再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种) Task> TrackingBatchDeleteAsync(Expression> deleteFilter); - /// EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息 - Task UpdatePartialAsync(TEntity entity, Expression> updateFactory, + /// EF跟踪方式 已有查询好的,再更新部分字段 稽查的时候需要完整的实体信息 + Task PartialUpdateAsync(TEntity entity, Expression> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default); /// EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息 - Task UpdatePartialSearchFirstAsync(Guid id, Expression> updateFactory, + Task QueryThenPartiallyUpdateAsync(Guid id, Expression> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default); - + + Task QueryThenPartiallyUpdateAsync(Expression> updateFilter, + Expression> updateFactory, + bool autoSave = false, CancellationToken cancellationToken = default); + + } diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 55e0af46b..26e5dfc08 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -228,7 +228,7 @@ namespace IRaCIS.Core.Infra.EFCore /// EF跟踪方式 外层先有查询好的完成实体,再更新部分字段 稽查的时候需要完整的实体信息 - public async Task UpdatePartialAsync(TEntity waitModifyEntity, Expression> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default) + public async Task PartialUpdateAsync(TEntity waitModifyEntity, Expression> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default) { var entityEntry = _dbContext.Entry(waitModifyEntity); entityEntry.State = EntityState.Detached; @@ -240,7 +240,7 @@ namespace IRaCIS.Core.Infra.EFCore } - public async Task UpdatePartialSearchFirstAsync(Expression> updateFilter, + public async Task QueryThenPartiallyUpdateAsync(Expression> updateFilter, Expression> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default) { @@ -253,14 +253,14 @@ namespace IRaCIS.Core.Infra.EFCore foreach (var needUpdateEntity in searchEntityList) { - await UpdatePartialAsync(needUpdateEntity, updateFactory, autoSave); + await PartialUpdateAsync(needUpdateEntity, updateFactory, autoSave); } } /// EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息 - public async Task UpdatePartialSearchFirstAsync(Guid id, Expression> updateFactory, + public async Task QueryThenPartiallyUpdateAsync(Guid id, Expression> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default) { //不跟踪 查询出来的实体就是Detached @@ -281,7 +281,7 @@ namespace IRaCIS.Core.Infra.EFCore return searchEntity; } - + /// 应用更新后拥有完整的实体信息,便于稽查 private void ModifyPartialFiled(TEntity waitModifyEntity, Expression> updateFactory) { List list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)