IRepositoryWithTKey.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. Task<TKey> AddAsync(TEntity entity, bool isCreator, CancellationToken cancellationToken = default);
  10. /// <summary>
  11. /// 批量插入(应用场景:小数据量,超出1万条建议另行实现)
  12. /// </summary>
  13. /// <param name="entities"></param>
  14. /// <param name="cancellationToken"></param>
  15. /// <returns></returns>
  16. Task AddRangeAsync(List<TEntity> entities, CancellationToken cancellationToken = default);
  17. Task RemoveAsync(TEntity entity, bool? soft = false, CancellationToken cancellationToken = default);
  18. Task RemoveAsync(TKey id, bool? soft = false, CancellationToken cancellationToken = default);
  19. Task RemoveAsync(Expression<Func<TEntity, bool>> predicate, bool? soft = false, CancellationToken cancellationToken = default);
  20. Task RemoveRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);
  21. Task RemoveRangeAsync(IEnumerable<TEntity> entities, bool? soft, CancellationToken cancellationToken = default);
  22. Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
  23. Task UpdateNullAsync(TEntity entity, CancellationToken cancellationToken = default);
  24. Task UpdateRangeAsync(List<TEntity> entities, CancellationToken cancellationToken = default);
  25. Task<TEntity?> GetAsync(TKey id, CancellationToken cancellationToken = default);
  26. Task<TEntity?> GetAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
  27. Task<TEntity?> GetAsync(Expression<Func<TEntity, bool>> predicate, bool isDesc, Expression<Func<TEntity, object>> orderBy, CancellationToken cancellationToken = default);
  28. Task<List<TEntity>> QueryAsync(
  29. Expression<Func<TEntity, bool>>? predicate = null,
  30. params (bool isWhere, Expression<Func<TEntity, bool>> expression)[] whereIfs);
  31. Task<bool> AnyAsync(CancellationToken cancellationToken = default);
  32. Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
  33. Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
  34. }
  35. }