修改仓储
This commit is contained in:
@@ -9,25 +9,58 @@ using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore
|
||||
{
|
||||
public interface ICommandRepository<TEntity>: ICommandRepository<TEntity, Guid> where TEntity : Entity
|
||||
public interface ICommandRepository<TEntity> : ICommandRepository<TEntity, Guid> where TEntity : Entity
|
||||
{
|
||||
|
||||
Task<TEntity> InsertOrUpdateAsync<TFrom>(TFrom from, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
Task<TEntity> InsertFromDTOAsync<TFrom>(TFrom from, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
/// <summary> EF 跟踪方式,先查询出完整的实体</summary>
|
||||
|
||||
Task<TEntity> UpdateFromDTOAsync<TFrom>(TFrom from, bool autoSave = false, bool ignoreDtoNullProperty = true, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
/// <summary>EF跟踪方式 生成 部分字段更新 (只更新传递的字段名 new[] {nameof(User.Name), nameof(User.Age))</summary>
|
||||
Task<TEntity> UpdatePartialFieldsAsync(TEntity entity, string[] propertyNames, bool autoSave = false, bool ignoreEntityNullProperty = true, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
/// <summary>EF跟踪方式 生成 部分字段立即更新,默认会去处理更新更新人 更新时间</summary>
|
||||
|
||||
Task<bool> UpdateNowNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
/// <summary> EF跟踪方式 生成 部分字段更新, 通过主键id 和表达式树 更新部分字段,默认不提交事务,一般用于服务里面 和别的操作 一起提交事务</summary>
|
||||
Task UpdateNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
|
||||
#region EF 跟踪方式删除 (先查询完整实体,再删除)
|
||||
|
||||
/// <summary>批量删除,EF跟踪方式(所有查询出来,再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
|
||||
Task<List<TEntity>> DeleteFromQueryAsync(Expression<Func<TEntity, bool>> deleteFilter, bool autoSave = false, bool ignoreQueryFilter = false);
|
||||
|
||||
Task<TEntity> DeleteFromQueryAsync(Guid id, bool autoSave = false, bool ignoreQueryFilter = false);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region EF跟踪方式 部分字段更新 会查询出来完整的实体
|
||||
|
||||
/// <summary> EF跟踪方式 已有查询好的,再更新部分字段 </summary>
|
||||
Task<bool> UpdateAsync(TEntity entity, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary> EF跟踪方式 先查询出来,再更新部分字段 </summary>
|
||||
Task<TEntity> UpdatePartialFromQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, bool ignoreQueryFilter = false, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary> EF跟踪方式 先查询出来所有实体,再更新部分字段 </summary>
|
||||
Task UpdatePartialFromQueryAsync(Expression<Func<TEntity, bool>> updateFilter,
|
||||
Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, bool ignoreQueryFilter = false, CancellationToken cancellationToken = default);
|
||||
|
||||
#endregion
|
||||
|
||||
#region EF跟踪方式 部分字段更新,不会去数据库查询完整实体
|
||||
|
||||
/// <summary>EF跟踪方式 生成 部分字段立即更新,不会去数据库查询完整的实体</summary>
|
||||
|
||||
Task<bool> UpdatePartialNowNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
/// <summary> EF跟踪方式 生成 部分字段更新,不会去数据库查询完整的实体</summary>
|
||||
Task UpdatePartialNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify);
|
||||
#endregion
|
||||
|
||||
#region 不走EF 跟踪机制,直接生成sql 批量更新或者删除
|
||||
|
||||
/// <summary>批量删除,相当于原生sql, 没用EF跟踪方式(所有查询出来,再删除 浪费性能)</summary>
|
||||
Task<bool> BatchDeleteNoTrackingAsync(Expression<Func<TEntity, bool>> deleteFilter);
|
||||
@@ -35,45 +68,32 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
/// <summary>批量更新,相当于原生sql, 没用EF跟踪方式(所有查询出来,再更新 浪费性能)</summary>
|
||||
Task<bool> BatchUpdateNoTrackingAsync(Expression<Func<TEntity, bool>> where, Expression<Func<TEntity, TEntity>> updateFactory);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
/// <summary>批量删除,EF跟踪方式(所有查询出来,再删除 浪费性能,但是稽查 或者触发某些操作时,需要知道数据库实体信息 不可避免用这种)</summary>
|
||||
Task<List<TEntity>> DeleteFromQueryAsync(Expression<Func<TEntity, bool>> deleteFilter, bool autoSave = false,bool ignoreQueryFilter = false);
|
||||
|
||||
Task<TEntity> DeleteFromQueryAsync(Guid id, bool autoSave = false, bool ignoreQueryFilter = false);
|
||||
|
||||
/// <summary> EF跟踪方式 已有查询好的,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
Task<bool> UpdateAsync(TEntity entity, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary> EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
Task<TEntity> UpdateFromQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, bool ignoreQueryFilter = false, CancellationToken cancellationToken = default);
|
||||
|
||||
Task UpdateFromQueryAsync(Expression<Func<TEntity, bool>> updateFilter,
|
||||
Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false , bool ignoreQueryFilter = false,CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary> 不常用 暂时废弃</summary>
|
||||
Task<TEntity> UpdatePartialFieldsAsync(TEntity entity, string[] propertyNames, bool autoSave = false, bool ignoreEntityNullProperty = true, params EntityVerifyExp<TEntity>[] verify);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public interface ICommandRepository<TEntity, TKey> where TEntity : class
|
||||
public interface ICommandRepository<TEntity, TKey> where TEntity : class
|
||||
{
|
||||
EntityEntry<TEntity> Attach(TEntity entity);
|
||||
|
||||
EntityEntry Entry(TEntity t);
|
||||
EntityEntry Entry(TEntity t);
|
||||
|
||||
Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> exp = null, bool ignoreQueryFilters = false);
|
||||
|
||||
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> exp,bool ignoreQueryFilters=false);
|
||||
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> exp, bool ignoreQueryFilters = false);
|
||||
|
||||
Task<TResult> MaxAsync<TResult>(Expression<Func<TEntity, TResult>> selector);
|
||||
|
||||
Task<int> CountAsync(Expression<Func<TEntity, bool>> whereLambda = null, bool ignoreQueryFilters = false);
|
||||
|
||||
ValueTask<TEntity> AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default,bool isSaveAudit=false);
|
||||
ValueTask<TEntity> AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default, bool isSaveAudit = false);
|
||||
|
||||
Task<IEnumerable<TEntity>> AddRangeAsync(IEnumerable<TEntity> entities, bool isSaveAudit = false);
|
||||
|
||||
@@ -87,10 +107,6 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
|
||||
|
||||
//Task<bool> DeleteManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default);
|
||||
//Task<bool> UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = 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 UpdateNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory, bool autoSave = false, params EntityVerifyExp<TEntity>[] verify)
|
||||
public async Task UpdatePartialNoQueryAsync(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> UpdateNowNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
public async Task<bool> UpdatePartialNowNoQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
params EntityVerifyExp<TEntity>[] verify)
|
||||
{
|
||||
await SetPartialFieldUpdateAsync(id, updateFactory, verify);
|
||||
@@ -242,7 +242,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
|
||||
|
||||
/// <summary>EF跟踪方式 先查询出来,再更新部分字段 稽查的时候需要完整的实体信息</summary>
|
||||
public async Task<TEntity> UpdateFromQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
public async Task<TEntity> UpdatePartialFromQueryAsync(Guid id, Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, bool ignoreQueryFilter = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
@@ -265,7 +265,7 @@ namespace IRaCIS.Core.Infra.EFCore
|
||||
return searchEntity;
|
||||
}
|
||||
|
||||
public async Task UpdateFromQueryAsync(Expression<Func<TEntity, bool>> updateFilter,
|
||||
public async Task UpdatePartialFromQueryAsync(Expression<Func<TEntity, bool>> updateFilter,
|
||||
Expression<Func<TEntity, TEntity>> updateFactory,
|
||||
bool autoSave = false, bool ignoreQueryFilter = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user