using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Text; using System.Threading; using System.Threading.Tasks; using IRaCIS.Core.Domain.Models; using Microsoft.EntityFrameworkCore.ChangeTracking; namespace IRaCIS.Core.Infra.EFCore { public interface ICommandRepository: ICommandRepository where TEntity : Entity { Task InsertOrUpdateAsync(TFrom from, bool autoSave = false, params EntityVerifyExp[] verify); Task InsertFromDTOAsync(TFrom from, bool autoSave = false, params EntityVerifyExp[] verify); Task UpdateFromDTOAsync(TFrom from, bool autoSave = false, bool ignoreDtoNullProperty = true, params EntityVerifyExp[] verify); 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); /// 批量删除,相当于原生sql, 没用EF跟踪方式(所有查询出来,再删除 浪费性能) Task BatchDeleteAsync(Expression> deleteFilter); /// 批量更新,相当于原生sql, 没用EF跟踪方式(所有查询出来,再更新 浪费性能) Task BatchUpdateAsync(Expression> where, Expression> updateFactory); } public interface ICommandRepository where TEntity : class { EntityEntry Attach(TEntity entity); EntityEntry Entry(TEntity t); Task FirstOrDefaultAsync(Expression> exp = null, bool ignoreQueryFilters = false); Task AnyAsync(Expression> exp,bool ignoreQueryFilters=false); Task MaxAsync(Expression> selector); Task CountAsync(Expression> whereLambda = null, bool ignoreQueryFilters = false); ValueTask AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); Task> AddRangeAsync(IEnumerable entities); Task AddRangeAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default); // 不建议使用,使用跟踪,然后save 部分字段更新,此种方式是更新所有字段 Task UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); Task SaveChangesAsync(CancellationToken cancellationToken = default); Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); //Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default); //Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default); } }