diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs index e4906fa03f..ad91a5367b 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs @@ -53,6 +53,13 @@ namespace Volo.Abp.Domain.Repositories { return Task.FromResult(GetList(includeDetails)); } + + public abstract long GetCount(); + + public virtual Task GetCountAsync(CancellationToken cancellationToken = default) + { + return Task.FromResult(GetCount()); + } } public abstract class BasicRepositoryBase : BasicRepositoryBase, IBasicRepository diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs index fc3a6f5b00..c67b35794b 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs @@ -23,6 +23,16 @@ namespace Volo.Abp.Domain.Repositories /// A to observe while waiting for the task to complete. /// Entity Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default); + + /// + /// Gets total count of all entities. + /// + long GetCount(); + + /// + /// Gets total count of all entities. + /// + Task GetCountAsync(CancellationToken cancellationToken = default); } public interface IReadOnlyBasicRepository : IReadOnlyBasicRepository diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index f9b7d265c3..acf4d7ce80 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -119,11 +119,21 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore : DbSet.ToList(); } - public override Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) + public override async Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) { return includeDetails - ? WithDetails().ToListAsync(cancellationToken) - : DbSet.ToListAsync(cancellationToken); + ? await WithDetails().ToListAsync(cancellationToken) + : await DbSet.ToListAsync(cancellationToken); + } + + public override long GetCount() + { + return DbSet.LongCount(); + } + + public override async Task GetCountAsync(CancellationToken cancellationToken = default) + { + return await DbSet.LongCountAsync(cancellationToken); } protected override IQueryable GetQueryable() diff --git a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index a3c11ed062..c658a34ef4 100644 --- a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -45,7 +45,12 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb { return Collection.ToList(); } - + + public override long GetCount() + { + return Collection.Count; + } + protected override IQueryable GetQueryable() { return ApplyDataFilters(Collection.AsQueryable()); diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 45621a189c..b7e2cf2a16 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -183,6 +183,16 @@ namespace Volo.Abp.Domain.Repositories.MongoDB return await GetMongoQueryable().ToListAsync(cancellationToken); } + public override long GetCount() + { + return GetMongoQueryable().LongCount(); + } + + public override async Task GetCountAsync(CancellationToken cancellationToken = default) + { + return await GetMongoQueryable().LongCountAsync(cancellationToken); + } + public override void Delete(Expression> predicate, bool autoSave = false) { var entities = GetMongoQueryable() diff --git a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs index 0e9cb4f8b5..24f14ddf6e 100644 --- a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs +++ b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs @@ -259,6 +259,11 @@ namespace Volo.Abp.Domain.Repositories throw new NotImplementedException(); } + public override long GetCount() + { + throw new NotImplementedException(); + } + protected override IQueryable GetQueryable() { throw new NotImplementedException();