Skip to content

Count Operations

Furkan Güngör edited this page Jun 20, 2022 · 2 revisions

Summary

Count queries can be run with EasyRepository.

Only Count

public class MyClass
{
    private readonly IUnitOfWork _unitOfWork;
    public MyClass(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public async Task<int> CountAsync()
    {
         return await _unitOfWork.Repository.CountAsync<Author>();
    }
}

Count With Classic Where Expression

public class MyClass
{
    private readonly IUnitOfWork _unitOfWork;
    public MyClass(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public async Task<int> CountWithClassicWhereAsync()
    {
         return await _unitOfWork.Repository.CountAsync<Author>(a=>a.Surname.Contains("t"));
    }
}

Count With AutoFilterer

public class MyClass
{
    private readonly IUnitOfWork _unitOfWork;
    public MyClass(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public async Task<int> CountWithAutoFiltererAsync(AuthorFilterDto dto)
    {
         return await _unitOfWork.Repository.CountAsync<Author, AuthorFilterDto>(dto);
    }
}
Clone this wiki locally