IRepositoryWithTKey.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Linq.Expressions;
  2. using XF.Domain.Entities;
  3. namespace XF.Domain.Repository
  4. {
  5. public interface IRepositoryWithTKey<TEntity, TKey>
  6. where TEntity : class, IEntity<TKey>, new() where TKey : IEquatable<TKey>
  7. {
  8. Task<TKey> AddAsync(TEntity entity, CancellationToken cancellationToken = default);
  9. /// <summary>
  10. /// 批量插入(应用场景:小数据量,超出1万条建议另行实现)
  11. /// </summary>
  12. /// <param name="entities"></param>
  13. /// <param name="cancellationToken"></param>
  14. /// <returns></returns>
  15. Task AddRangeAsync(List<TEntity> entities, CancellationToken cancellationToken = default);
  16. Task RemoveAsync(TEntity entity, bool? soft = false, CancellationToken cancellationToken = default);
  17. Task RemoveAsync(TKey id, bool? soft = false, CancellationToken cancellationToken = default);
  18. Task RemoveAsync(Expression<Func<TEntity, bool>> predicate, bool? soft = false, CancellationToken cancellationToken = default);
  19. Task RemoveRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);
  20. Task RemoveRangeAsync(IEnumerable<TEntity> entities, bool? soft, CancellationToken cancellationToken = default);
  21. Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
  22. Task UpdateRangeAsync(List<TEntity> entities, CancellationToken cancellationToken = default);
  23. Task<TEntity?> GetAsync(TKey id, CancellationToken cancellationToken = default);
  24. Task<TEntity?> GetAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
  25. Task<TEntity?> GetAsync(Expression<Func<TEntity, bool>> predicate, bool isDesc, Expression<Func<TEntity, object>> orderBy, CancellationToken cancellationToken = default);
  26. Task<List<TEntity>> QueryAsync(
  27. Expression<Func<TEntity, bool>>? predicate = null,
  28. params (bool isWhere, Expression<Func<TEntity, bool>> expression)[] whereIfs);
  29. Task<bool> AnyAsync(CancellationToken cancellationToken = default);
  30. Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
  31. Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
  32. }
  33. }