修改仓储

Uat_Study
hang 2022-04-26 09:34:41 +08:00
parent cf08b85811
commit bf693c8bc3
2 changed files with 14 additions and 9 deletions

View File

@ -37,14 +37,19 @@ namespace IRaCIS.Core.Infra.EFCore
/// <summary>批量删除EF跟踪方式所有查询出来再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
Task<List<TEntity>> TrackingBatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter);
/// <summary> EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
Task<bool> UpdatePartialAsync(TEntity entity, Expression<Func<TEntity, TEntity>> updateFactory,
/// <summary> EF跟踪方式 已有查询好的,再更新部分字段 稽查的时候需要完整的实体信息</summary>
Task<bool> PartialUpdateAsync(TEntity entity, Expression<Func<TEntity, TEntity>> updateFactory,
bool autoSave = false, CancellationToken cancellationToken = default);
/// <summary> EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
Task<TEntity> UpdatePartialSearchFirstAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
Task<TEntity> QueryThenPartiallyUpdateAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
bool autoSave = false, CancellationToken cancellationToken = default);
Task QueryThenPartiallyUpdateAsync(Expression<Func<TEntity, bool>> updateFilter,
Expression<Func<TEntity, TEntity>> updateFactory,
bool autoSave = false, CancellationToken cancellationToken = default);
}

View File

@ -228,7 +228,7 @@ namespace IRaCIS.Core.Infra.EFCore
/// <summary>EF跟踪方式 外层先有查询好的完成实体,再更新部分字段 稽查的时候需要完整的实体信息</summary>
public async Task<bool> UpdatePartialAsync(TEntity waitModifyEntity, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default)
public async Task<bool> PartialUpdateAsync(TEntity waitModifyEntity, Expression<Func<TEntity, TEntity>> 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<Func<TEntity, bool>> updateFilter,
public async Task QueryThenPartiallyUpdateAsync(Expression<Func<TEntity, bool>> updateFilter,
Expression<Func<TEntity, TEntity>> 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);
}
}
/// <summary>EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
public async Task<TEntity> UpdatePartialSearchFirstAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
public async Task<TEntity> QueryThenPartiallyUpdateAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
bool autoSave = false, CancellationToken cancellationToken = default)
{
//不跟踪 查询出来的实体就是Detached
@ -281,7 +281,7 @@ namespace IRaCIS.Core.Infra.EFCore
return searchEntity;
}
/// <summary>应用更新后拥有完整的实体信息,便于稽查</summary>
private void ModifyPartialFiled(TEntity waitModifyEntity, Expression<Func<TEntity, TEntity>> updateFactory)
{
List<PropertyInfo> list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)