diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index e2abb30d..e04b32ca 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -20,9 +20,13 @@ namespace IRaCIS.Core.Infra.EFCore Task UpdatePartialFields(TEntity entity, string[] propertyNames, bool autoSave = false, bool ignoreEntityNullProperty = true, params EntityVerifyExp[] verify); + Task UpdatePartialFieldsNow(Guid id, Expression> updateFactory, params EntityVerifyExp[] verify); + + Task UpdatePartialFields(Guid id, Expression> updateFactory, bool autoSave = false, params EntityVerifyExp[] verify); + Task BatchDeleteAsync(Expression> deleteFilter); Task BatchUpdateAsync(Expression> where, Expression> updateFactory); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 40dabcdc..98e53bef 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -23,7 +23,7 @@ namespace IRaCIS.Core.Infra.EFCore public class Repository : IRepository where TEntity : Entity, new() { - + public IMapper _mapper { get; set; } public IRaCISDBContext _dbContext { get; set; } @@ -31,12 +31,12 @@ namespace IRaCIS.Core.Infra.EFCore public IUserInfo _userInfo { get; set; } - public Repository(IRaCISDBContext dbContext, IMapper mapper,IUserInfo userInfo) + public Repository(IRaCISDBContext dbContext, IMapper mapper, IUserInfo userInfo) { _dbContext = dbContext; _mapper = mapper; _userInfo = userInfo; - + } #region 异步部分 @@ -113,7 +113,7 @@ namespace IRaCIS.Core.Infra.EFCore //} var createtime = DateTime.Now.AddSeconds(1); - + // 受试者 if (typeof(TEntity) == typeof(Subject)) { @@ -343,7 +343,7 @@ namespace IRaCIS.Core.Infra.EFCore var dbEntityProp = typeof(TEntity).GetProperties(); foreach (var propertyInfo in from.GetType().GetProperties()) { - if (propertyInfo.GetValue(from) == null && dbEntityProp.Any(t=>t.Name== propertyInfo.Name)) + if (propertyInfo.GetValue(from) == null && dbEntityProp.Any(t => t.Name == propertyInfo.Name)) { _dbContext.Entry(dbEntity).Property(propertyInfo.Name).IsModified = false; } @@ -378,6 +378,21 @@ namespace IRaCIS.Core.Infra.EFCore /// /// public async Task UpdatePartialFields(Guid id, Expression> updateFactory, bool autoSave = false, params EntityVerifyExp[] verify) + { + await SetPartialFieldUpdateAsync(id, updateFactory, verify); + + await SaveChangesAsync(autoSave); + + } + + public async Task UpdatePartialFieldsNow(Guid id, Expression> updateFactory, + params EntityVerifyExp[] verify) + { + await SetPartialFieldUpdateAsync(id, updateFactory, verify); + return await SaveChangesAsync(true); + } + + private async Task SetPartialFieldUpdateAsync(Guid id, Expression> updateFactory, params EntityVerifyExp[] 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 } - /// /// 部分字段更新 (只更新传递的字段名 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)) @@ -465,7 +476,7 @@ namespace IRaCIS.Core.Infra.EFCore public async Task UpdateExcludeFields(TEntity entity, string[] propertyNames, bool autoSave = false, bool ignoreEntityNullProperty = true, params EntityVerifyExp[] verify) { - await EntityVerifyAsync(false, verify, entity.Id); + await EntityVerifyAsync(false, verify, entity.Id); var entityEntry = _dbContext.Entry(entity); entityEntry.State = EntityState.Modified;