Skip to content

Select Operations

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

Summary

You can run your select expressions with EasyRepository.

Only Select

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

    public async Task<object> GetSelectableMultipleAsync()
    {
        var entities = await _unitOfWork.Repository.GetMultipleAsync<Author, object>(asNoTracking: false, projectExpression: select => new
        {
            SelectName = select.Name,
            SelectDate = select.CreationDate
        });
        return entities;
    }
}

Include, Select and Where

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

    public async Task<object> GetFilterableAndIncludeableMultipleAsync()
    {
        Func<IQueryable<Author>, IIncludableQueryable<Author, object>> include = a => a.Include(i => i.Books);
        var entities = await _unitOfWork.Repository.GetMultipleAsync<Author, object>(asNoTracking: false, whereExpression: a=>a.IsDeleted == false, includeExpression: include, projectExpression: select => new
        {
            SelectName = select.Name,
            SelectDate = select.CreationDate
        });
        return entities;
    }
}
Clone this wiki locally