diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyRepository.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyRepository.cs index 03aad9c048..499a1e58be 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyRepository.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyRepository.cs @@ -2,12 +2,15 @@ using System.Linq; using System.Linq.Expressions; using Volo.Abp.Domain.Entities; +using Volo.Abp.Linq; namespace Volo.Abp.Domain.Repositories { public interface IReadOnlyRepository : IQueryable, IReadOnlyBasicRepository where TEntity : class, IEntity { + IAsyncQueryableExecuter AsyncExecuter { get; } + IQueryable WithDetails(); IQueryable WithDetails(params Expression>[] propertySelectors); diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryAsyncExtensions.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryAsyncExtensions.cs new file mode 100644 index 0000000000..7cddb753c9 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryAsyncExtensions.cs @@ -0,0 +1,41 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.Domain.Repositories +{ + public static class RepositoryAsyncExtensions + { + #region Count/LongCount + + public static Task CountAsync( + [NotNull] this IReadOnlyRepository repository, + CancellationToken cancellationToken = default) + where T : class, IEntity + { + return repository.AsyncExecuter.CountAsync( + repository, + cancellationToken + ); + } + + public static Task CountAsync( + [NotNull] this IReadOnlyRepository repository, + [NotNull] Expression> predicate, + CancellationToken cancellationToken = default) + where T : class, IEntity + { + return repository.AsyncExecuter.CountAsync( + repository, + predicate, + cancellationToken + ); + } + + #endregion + } +} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs index bd7e486d29..fd66b293c9 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp.Data; using Volo.Abp.Domain.Entities; +using Volo.Abp.Linq; using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; @@ -19,6 +20,8 @@ namespace Volo.Abp.Domain.Repositories public ICurrentTenant CurrentTenant { get; set; } + public IAsyncQueryableExecuter AsyncExecuter { get; set; } + public IUnitOfWorkManager UnitOfWorkManager { get; set; } public virtual Type ElementType => GetQueryable().ElementType; @@ -50,12 +53,12 @@ namespace Volo.Abp.Domain.Repositories protected abstract IQueryable GetQueryable(); public abstract Task FindAsync( - Expression> predicate, + Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default); public async Task GetAsync( - Expression> predicate, + Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) { @@ -107,4 +110,4 @@ namespace Volo.Abp.Domain.Repositories await DeleteAsync(entity, autoSave, cancellationToken); } } -} \ No newline at end of file +}