12345678910111213141516171819202122232425262728293031323334353637 |
- using System.Linq.Expressions;
- using XF.Domain.Entities;
- namespace XF.Domain.Repository
- {
- public interface IRepositoryWithTKey<TEntity, TKey>
- where TEntity : class, IEntity<TKey>, new() where TKey : IEquatable<TKey>
- {
- Task<TKey> AddAsync(TEntity entity, CancellationToken cancellationToken = default);
- /// <summary>
- /// 批量插入(应用场景:小数据量,超出1万条建议另行实现)
- /// </summary>
- /// <param name="entities"></param>
- /// <param name="cancellationToken"></param>
- /// <returns></returns>
- Task AddRangeAsync(List<TEntity> entities, CancellationToken cancellationToken = default);
- Task RemoveAsync(TEntity entity, bool? soft = false, CancellationToken cancellationToken = default);
- Task RemoveAsync(TKey id, bool? soft = false, CancellationToken cancellationToken = default);
- Task RemoveAsync(Expression<Func<TEntity, bool>> predicate, bool? soft = false, CancellationToken cancellationToken = default);
- Task RemoveRangeAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);
- Task RemoveRangeAsync(IEnumerable<TEntity> entities, bool? soft, CancellationToken cancellationToken = default);
- Task UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
- Task UpdateRangeAsync(List<TEntity> entities, CancellationToken cancellationToken = default);
- Task<TEntity?> GetAsync(TKey id, CancellationToken cancellationToken = default);
- Task<TEntity?> GetAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
- Task<TEntity?> GetAsync(Expression<Func<TEntity, bool>> predicate, bool isDesc, Expression<Func<TEntity, object>> orderBy, CancellationToken cancellationToken = default);
- Task<List<TEntity>> QueryAsync(
- Expression<Func<TEntity, bool>>? predicate = null,
- params (bool isWhere, Expression<Func<TEntity, bool>> expression)[] whereIfs);
- Task<bool> AnyAsync(CancellationToken cancellationToken = default);
- Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
- Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
- }
- }
|