Added GetCount to the repository.

pull/395/head
Halil ibrahim Kalkan 7 years ago
parent 250f2d1f8a
commit bcf445928b

@ -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>

@ -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>

@ -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()

@ -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());

@ -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()

@ -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