部分更新 立即提交事务
parent
0f6bae867c
commit
01c38bbd63
|
@ -20,9 +20,13 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
|
||||
Task<TEntity> UpdatePartialFields(TEntity entity, string[] propertyNames, bool autoSave = false, bool ignoreEntityNullProperty = true, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
Task<bool> UpdatePartialFieldsNow(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
|
||||
Task UpdatePartialFields(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
|
||||
|
||||
Task<bool> BatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter);
|
||||
Task<bool> BatchUpdateAsync(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TEntity>> updateFactory);
|
||||
|
||||
|
|
|
@ -378,6 +378,21 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
/// <param name="verify"></param>
|
||||
/// <returns></returns>
|
||||
public async Task UpdatePartialFields(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify)
|
||||
{
|
||||
await SetPartialFieldUpdateAsync(id, updateFactory, verify);
|
||||
|
||||
await SaveChangesAsync(autoSave);
|
||||
|
||||
}
|
||||
|
||||
public async Task<bool> UpdatePartialFieldsNow(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
params EntityVerifyExp<TEntity>[] verify)
|
||||
{
|
||||
await SetPartialFieldUpdateAsync(id, updateFactory, verify);
|
||||
return await SaveChangesAsync(true);
|
||||
}
|
||||
|
||||
private async Task SetPartialFieldUpdateAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, params EntityVerifyExp<TEntity>[] verify)
|
||||
{
|
||||
await EntityVerifyAsync(false, verify, id);
|
||||
|
||||
|
@ -403,9 +418,6 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
_dbContext.Entry(entity).Property(prop.Name).IsModified = true;
|
||||
}
|
||||
|
||||
|
||||
await SaveChangesAsync(autoSave);
|
||||
|
||||
#region Test
|
||||
|
||||
|
||||
|
@ -422,7 +434,6 @@ namespace IRaCIS.Core.Infra.EFCore
|
|||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 部分字段更新 (只更新传递的字段名 new[] {nameof(User.Name), nameof(User.Age))
|
||||
/// new Dictionary() { ParentId = null, Code = "test",Id=Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584")},new[] {nameof(Dictionary.Name), nameof(Dictionary.Age))
|
||||
|
|
Loading…
Reference in New Issue