修改仓储名称
This commit is contained in:
@@ -22,36 +22,38 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
/// <summary>EF跟踪方式 生成 部分字段立即更新,默认会去处理更新更新人 更新时间</summary>
|
||||
|
||||
Task<bool> UpdatePartialFieldsNowAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, params EntityVerifyExp<TEntity>[] verify);
|
||||
Task<bool> UpdateNowNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
/// <summary> EF跟踪方式 生成 部分字段更新, 通过主键id 和表达式树 更新部分字段,默认不提交事务,一般用于服务里面 和别的操作 一起提交事务</summary>
|
||||
Task UpdatePartialFieldsAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
||||
Task UpdateNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
|
||||
|
||||
/// <summary>批量删除,相当于原生sql, 没用EF跟踪方式(所有查询出来,再删除 浪费性能)</summary>
|
||||
Task<bool> BatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter);
|
||||
Task<bool> BatchDeleteNoTrackingAsync(Expression<Func<TEntity, bool>> deleteFilter);
|
||||
|
||||
/// <summary>批量更新,相当于原生sql, 没用EF跟踪方式(所有查询出来,再更新 浪费性能)</summary>
|
||||
Task<bool> BatchUpdateAsync(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TEntity>> updateFactory);
|
||||
Task<bool> BatchUpdateNoTrackingAsync(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TEntity>> updateFactory);
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>批量删除,EF跟踪方式(所有查询出来,再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
|
||||
Task<List<TEntity>> TrackingDeleteFromQueryAsync(Expression<Func<TEntity, bool>> deleteFilter, bool autoSave = false);
|
||||
Task<List<TEntity>> DeleteFromQueryAsync(Expression<Func<TEntity, bool>> deleteFilter, bool autoSave = false,bool ignoreQueryFilter = false);
|
||||
|
||||
Task<TEntity> TrackingDeleteFromQueryAsync(Guid id, bool autoSave = false);
|
||||
Task<TEntity> DeleteFromQueryAsync(Guid id, bool autoSave = false, bool ignoreQueryFilter = false);
|
||||
|
||||
/// <summary> EF跟踪方式 已有查询好的,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
Task<bool> TrackingUpdateAsync(TEntity entity, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
Task<bool> UpdateAsync(TEntity entity, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary> EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
Task<TEntity> TrackingUpdateFromQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, CancellationToken cancellationToken = default);
|
||||
Task<TEntity> UpdateFromQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, bool ignoreQueryFilter = false, CancellationToken cancellationToken = default);
|
||||
|
||||
Task TrackingUpdateFromQueryAsync(Expression<Func<TEntity, bool>> updateFilter,
|
||||
Task UpdateFromQueryAsync(Expression<Func<TEntity, bool>> updateFilter,
|
||||
Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, CancellationToken cancellationToken = default);
|
||||
bool autoSave = false , bool ignoreQueryFilter = false,CancellationToken cancellationToken = default);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
/// <summary> EF跟踪方式 生成 部分字段更新, 通过主键id 和表达式树 更新部分字段
|
||||
/// 例如 Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"),u => new Dictionary() { ParentId = null, Code = "test" }默认会去处理更新更新人 更新时间</summary>
|
||||
|
||||
public async Task UpdatePartialFieldsAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify)
|
||||
public async Task UpdateNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify)
|
||||
{
|
||||
await SetPartialFieldUpdateAsync(id, updateFactory, verify);
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
|
||||
/// <summary> EF跟踪方式 生成 部分字段立即更新,默认会去处理更新更新人 更新时间 </summary>
|
||||
public async Task<bool> UpdatePartialFieldsNowAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
public async Task<bool> UpdateNowNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
params EntityVerifyExp<TEntity>[] verify)
|
||||
{
|
||||
await SetPartialFieldUpdateAsync(id, updateFactory, verify);
|
||||
@@ -226,27 +226,10 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
|
||||
|
||||
public async Task TrackingUpdateFromQueryAsync(Expression<Func<TEntity, bool>> updateFilter,
|
||||
Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (updateFilter == null)
|
||||
{
|
||||
throw new ArgumentException("更新过滤条件不允许为空", nameof(updateFilter));
|
||||
}
|
||||
|
||||
var searchEntityList = await _dbSet.AsNoTracking().Where(updateFilter).ToListAsync();
|
||||
|
||||
foreach (var needUpdateEntity in searchEntityList)
|
||||
{
|
||||
await TrackingUpdateAsync(needUpdateEntity, updateFactory, autoSave);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>EF跟踪方式 外层先有查询好的完成实体,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
public async Task<bool> TrackingUpdateAsync(TEntity waitModifyEntity, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||
public async Task<bool> UpdateAsync(TEntity waitModifyEntity, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entityEntry = _dbContext.Entry(waitModifyEntity);
|
||||
entityEntry.State = EntityState.Detached;
|
||||
@@ -259,14 +242,14 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
public async Task<TEntity> TrackingUpdateFromQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, CancellationToken cancellationToken = default)
|
||||
public async Task<TEntity> UpdateFromQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, bool ignoreQueryFilter = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
var query = ignoreQueryFilter ? _dbSet.AsNoTracking().IgnoreQueryFilters() : _dbSet.AsNoTracking();
|
||||
//不跟踪 查询出来的实体就是Detached
|
||||
var searchEntity = await _dbSet.AsNoTracking().IgnoreQueryFilters().FirstOrDefaultAsync(t => t.Id == id);
|
||||
var searchEntity = await query.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (searchEntity == null)
|
||||
{
|
||||
@@ -283,7 +266,27 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
return searchEntity;
|
||||
}
|
||||
|
||||
/// <summary>应用更新后拥有完整的实体信息,便于稽查</summary>
|
||||
public async Task UpdateFromQueryAsync(Expression<Func<TEntity, bool>> updateFilter,
|
||||
Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, bool ignoreQueryFilter = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (updateFilter == null)
|
||||
{
|
||||
throw new ArgumentException("更新过滤条件不允许为空", nameof(updateFilter));
|
||||
}
|
||||
var query = ignoreQueryFilter ? _dbSet.AsNoTracking().IgnoreQueryFilters() : _dbSet.AsNoTracking();
|
||||
|
||||
var searchEntityList = await query.Where(updateFilter).ToListAsync();
|
||||
|
||||
foreach (var needUpdateEntity in searchEntityList)
|
||||
{
|
||||
await UpdateAsync(needUpdateEntity, updateFactory, autoSave);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>更新后拥有完整的实体信息,便于稽查</summary>
|
||||
private void ModifyPartialFiled(TEntity waitModifyEntity, Expression<Func<TEntity, TEntity>> updateFactory)
|
||||
{
|
||||
List<PropertyInfo> list = ((MemberInitExpression)updateFactory.Body).Bindings.Select(mb => mb.Member.Name)
|
||||
@@ -318,9 +321,11 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
|
||||
/// <summary>EF跟踪方式(查询出来,再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
|
||||
public async Task<TEntity> TrackingDeleteFromQueryAsync(Guid id, bool autoSave = false)
|
||||
public async Task<TEntity> DeleteFromQueryAsync(Guid id, bool autoSave = false, bool ignoreQueryFilter = false)
|
||||
{
|
||||
var waitDelete = await _dbSet.IgnoreQueryFilters().Where(t=>t.Id== id).FirstOrDefaultAsync();
|
||||
var query = ignoreQueryFilter ? _dbSet.AsNoTracking().IgnoreQueryFilters() : _dbSet.AsNoTracking();
|
||||
|
||||
var waitDelete = await query.Where(t=>t.Id== id).FirstOrDefaultAsync();
|
||||
|
||||
if (waitDelete == null)
|
||||
{
|
||||
@@ -335,9 +340,10 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
|
||||
/// <summary>批量删除,EF跟踪方式(所有查询出来,再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
|
||||
public async Task<List<TEntity>> TrackingDeleteFromQueryAsync(Expression<Func<TEntity, bool>> deleteFilter, bool autoSave = false)
|
||||
public async Task<List<TEntity>> DeleteFromQueryAsync(Expression<Func<TEntity, bool>> deleteFilter, bool autoSave = false, bool ignoreQueryFilter = false)
|
||||
{
|
||||
var waitDeleteList = await _dbSet.IgnoreQueryFilters().Where(deleteFilter).ToListAsync();
|
||||
var query = ignoreQueryFilter ? _dbSet.AsNoTracking().IgnoreQueryFilters() : _dbSet.AsNoTracking();
|
||||
var waitDeleteList = await query.Where(deleteFilter).ToListAsync();
|
||||
|
||||
foreach (var deleteItem in waitDeleteList)
|
||||
{
|
||||
@@ -357,14 +363,14 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
#region 不走EF 跟踪机制的删除 更新 以及批量操作
|
||||
|
||||
/// <summary>批量删除,相当于原生sql, 没用EF跟踪方式(所有查询出来,再删除 浪费性能)</summary>
|
||||
public async Task<bool> BatchDeleteAsync(Expression<Func<TEntity, bool>> deleteFilter)
|
||||
public async Task<bool> BatchDeleteNoTrackingAsync(Expression<Func<TEntity, bool>> deleteFilter)
|
||||
{
|
||||
return await _dbSet.IgnoreQueryFilters().Where(deleteFilter).BatchDeleteAsync() > 0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>批量更新,相当于原生sql, 没用EF跟踪方式(所有查询出来,再更新 浪费性能)</summary>
|
||||
public async Task<bool> BatchUpdateAsync(Expression<Func<TEntity, bool>> where,
|
||||
public async Task<bool> BatchUpdateNoTrackingAsync(Expression<Func<TEntity, bool>> where,
|
||||
Expression<Func<TEntity, TEntity>> updateFactory)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user