仓储更新
parent
5d0c8a2cba
commit
4487235a97
|
@ -93,16 +93,21 @@ namespace IRaCIS.Core.Application.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var subject = (await _subjectRepository.FirstOrDefaultAsync(t => t.Id == svCommand.SubjectId)).IfNullThrowException();
|
|
||||||
|
|
||||||
|
|
||||||
//更新受试者 首次给药日期 是否入组确认
|
//更新受试者 首次给药日期 是否入组确认
|
||||||
if (svCommand.SubjectFirstGiveMedicineTime != null && svCommand.IsBaseLine)
|
if (svCommand.SubjectFirstGiveMedicineTime != null && svCommand.IsBaseLine)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//await _subjectRepository.UpdatePartialSearchFirstAsync(svCommand.SubjectId,
|
||||||
|
// u => new Subject() { FirstGiveMedicineTime = svCommand.SubjectFirstGiveMedicineTime });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var subject = (await _subjectRepository.FirstOrDefaultAsync(t => t.Id == svCommand.SubjectId)).IfNullThrowException();
|
||||||
|
|
||||||
// 更新受试者
|
// 更新受试者
|
||||||
subject.FirstGiveMedicineTime = svCommand.SubjectFirstGiveMedicineTime;
|
subject.FirstGiveMedicineTime = svCommand.SubjectFirstGiveMedicineTime;
|
||||||
|
|
||||||
|
|
||||||
List<DataInspection> datas = new List<DataInspection>();
|
List<DataInspection> datas = new List<DataInspection>();
|
||||||
|
|
||||||
datas.Add(new DataInspection()
|
datas.Add(new DataInspection()
|
||||||
|
|
|
@ -23,9 +23,12 @@ namespace IRaCIS.Application.Services
|
||||||
public string Get(testModel testModel)
|
public string Get(testModel testModel)
|
||||||
{
|
{
|
||||||
|
|
||||||
var d = _repository.Where<User>(t => t.FullName.Contains("cc")).Select(t => t.FullName).FirstOrDefault();
|
var tt= _dicRepository.UpdatePartialSearchFirstAsync(Guid.Parse("e2b97a6c-35a6-4aa3-7f27-08da13ab33ff"), t => new Dictionary() { Description = "xxxxx" }, true).Result;
|
||||||
var c = _dicRepository.Where(t => t.ParentId != null).Select(t => t.MappedValue).First();
|
|
||||||
CultureInfo culture = CultureInfo.CurrentUICulture;
|
|
||||||
|
//var d = _repository.Where<User>(t => t.FullName.Contains("cc")).Select(t => t.FullName).FirstOrDefault();
|
||||||
|
//var c = _dicRepository.Where(t => t.ParentId != null).Select(t => t.MappedValue).First();
|
||||||
|
//CultureInfo culture = CultureInfo.CurrentUICulture;
|
||||||
|
|
||||||
//var dd = _dicRepository.UpdatePartialFields(Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"),
|
//var dd = _dicRepository.UpdatePartialFields(Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"),
|
||||||
// u => new Dictionary() { ParentId = null, Code = "test" }, true);
|
// u => new Dictionary() { ParentId = null, Code = "test" }, true);
|
||||||
|
|
|
@ -37,6 +37,13 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
/// <summary>批量删除,EF跟踪方式(所有查询出来,再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
|
/// <summary>批量删除,EF跟踪方式(所有查询出来,再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
|
||||||
Task<List<TEntity>> TrackingBatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter);
|
Task<List<TEntity>> TrackingBatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter);
|
||||||
|
|
||||||
|
Task<bool> UpdatePartialAsync(TEntity entity, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||||
|
bool autoSave = false, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
Task<TEntity> UpdatePartialSearchFirstAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||||
|
bool autoSave = false, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ICommandRepository<TEntity, TKey> where TEntity : class
|
public interface ICommandRepository<TEntity, TKey> where TEntity : class
|
||||||
|
|
|
@ -207,7 +207,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
#region 异步 EF 跟踪 自动生成 更新 和删除语句
|
#region 异步 EF 跟踪 自动生成 更新 和删除语句
|
||||||
|
|
||||||
|
|
||||||
/// <summary>EF跟踪方式 更新,全字段更新</summary>
|
/// <summary>EF跟踪方式 更新,全字段更新 不好</summary>
|
||||||
public async Task<bool> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
|
public async Task<bool> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
_dbSet.Update(entity);
|
_dbSet.Update(entity);
|
||||||
|
@ -223,6 +223,70 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||||
|
public async Task<bool> UpdatePartialAsync(TEntity entity, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var entityEntry = _dbContext.Entry(entity);
|
||||||
|
|
||||||
|
|
||||||
|
entityEntry.State = EntityState.Detached;
|
||||||
|
|
||||||
|
|
||||||
|
List<PropertyInfo> list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)
|
||||||
|
.Select(propName => typeof(TEntity).GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)).ToList();
|
||||||
|
|
||||||
|
Func<TEntity, TEntity> func = updateFactory.Compile();
|
||||||
|
|
||||||
|
TEntity applyObj = func(entity);
|
||||||
|
|
||||||
|
foreach (PropertyInfo prop in list)
|
||||||
|
{
|
||||||
|
object value = prop.GetValue((object)applyObj);
|
||||||
|
prop.SetValue((object)entity, value);
|
||||||
|
|
||||||
|
_dbContext.Entry(entity).Property(prop.Name).IsModified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||||
|
public async Task<TEntity> UpdatePartialSearchFirstAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||||
|
bool autoSave = false, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var searchEntity = await _dbSet.AsNoTracking().FirstOrDefaultAsync(t => t.Id == id);
|
||||||
|
|
||||||
|
if (searchEntity == null)
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException(
|
||||||
|
" Update object not exist in db,Please check if the parameter Id is passed incorrectly");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<PropertyInfo> list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)
|
||||||
|
.Select(propName => typeof(TEntity).GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)).ToList();
|
||||||
|
|
||||||
|
Func<TEntity, TEntity> func = updateFactory.Compile();
|
||||||
|
|
||||||
|
TEntity applyObj = func(searchEntity);
|
||||||
|
|
||||||
|
foreach (PropertyInfo prop in list)
|
||||||
|
{
|
||||||
|
object value = prop.GetValue((object)applyObj);
|
||||||
|
prop.SetValue((object)searchEntity, value);
|
||||||
|
|
||||||
|
_dbContext.Entry(searchEntity).Property(prop.Name).IsModified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
await SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return searchEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>EF跟踪方式 删除</summary>
|
/// <summary>EF跟踪方式 删除</summary>
|
||||||
|
|
Loading…
Reference in New Issue