Browse Source

Added GetCount to the repository.

pull/395/head
Halil ibrahim Kalkan 8 years ago
parent
commit
bcf445928b
  1. 7
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs
  2. 10
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs
  3. 16
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  4. 7
      framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs
  5. 10
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  6. 5
      framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs

7
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<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(GetCount());
}
}
public abstract class BasicRepositoryBase<TEntity, TKey> : BasicRepositoryBase<TEntity>, IBasicRepository<TEntity, TKey>

10
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs

@ -23,6 +23,16 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>Entity</returns>
Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default);
/// <summary>
/// Gets total count of all entities.
/// </summary>
long GetCount();
/// <summary>
/// Gets total count of all entities.
/// </summary>
Task<long> GetCountAsync(CancellationToken cancellationToken = default);
}
public interface IReadOnlyBasicRepository<TEntity, TKey> : IReadOnlyBasicRepository<TEntity>

16
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<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
public override async Task<List<TEntity>> 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<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await DbSet.LongCountAsync(cancellationToken);
}
protected override IQueryable<TEntity> GetQueryable()

7
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<TEntity> GetQueryable()
{
return ApplyDataFilters(Collection.AsQueryable());

10
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<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().LongCountAsync(cancellationToken);
}
public override void Delete(Expression<Func<TEntity, bool>> predicate, bool autoSave = false)
{
var entities = GetMongoQueryable()

5
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<TEntity> GetQueryable()
{
throw new NotImplementedException();

Loading…
Cancel
Save