-
Notifications
You must be signed in to change notification settings - Fork 14
Get Single Operations
Furkan Güngör edited this page Jun 20, 2022
·
2 revisions
EasyRepository
contains two different methods for filter operations.
- Manual filter
- AutoFilterer
Based on your AutoFilterer
Dto (Data Transfer Object)
classes, it performs a dynamic query on the related entity.
Among the default features of AutoFilterer;
- Pagination
- Sorting
- Range (min-max)
- Contains
operations such as.
This repo contains limited information about AutoFilterer
. Visit the Auto Filterer Wiki for more information.
public class MyClass
{
private readonly IUnitOfWork _unitOfWork;
public MyClass(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task<Author> ClassicWhere()
{
var entity = await _unitOfWork.Repository.GetSingleAsync<Author>(false, whereExpression: a => a.IsDeleted == false);
// or
var entity2 = await _unitOfWork.Repository.GetSingleAsync<Author>(false, whereExpression: a => a.IsDeleted == false && a.Name.Contains("t"));
return entity;
}
}
[PossibleSortings("Name", "Surname", "CreationDate", "ModificationDate", "DeletionDate")]
public class AuthorFilterDto : PaginationFilterBase
{
public AuthorFilterDto()
{
this.Sort = "Name";
this.SortBy = AutoFilterer.Enums.Sorting.Descending;
}
[ToLowerContainsComparison]
public string Name { get; set; }
[ToLowerContainsComparison]
public string Surname { get; set; }
public Range<DateTime> CreationDate { get; set; }
public Range<DateTime> ModificationDate { get; set; }
public Range<DateTime> DeletionDate { get; set; }
}
public class MyClass
{
private readonly IUnitOfWork _unitOfWork;
public MyClass(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task<Author> AutoFilterer(AuthorFilterDto dto)
{
var entities = await _unitOfWork.Repository.GetSingleAsync<Author, AuthorFilterDto>(asNoTracking: false, dto);
return entities;
}
}
public class MyClass
{
private readonly IUnitOfWork _unitOfWork;
public MyClass(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task<Author> AutoFiltererWithInclude(AuthorFilterDto dto)
{
Func<IQueryable<Author>, IIncludableQueryable<Author, object>> include = a => a.Include(i => i.Books);
var entity = await _unitOfWork.Repository.GetSingleAsync<Author, AuthorFilterDto>(asNoTracking: false, dto, includeExpression: include);
return entity;
}
}
public class MyClass
{
private readonly IUnitOfWork _unitOfWork;
public MyClass(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task<object> AutoFiltererWithSelect(AuthorFilterDto dto)
{
var entity = await _unitOfWork.Repository.GetSingleAsync<Author, AuthorFilterDto, object>(asNoTracking: false, dto, select => new
{
SelectName = select.Name,
SelectDate = select.CreationDate
});
return entity;
}
}
public class MyClass
{
private readonly IUnitOfWork _unitOfWork;
public MyClass(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task<object> AutoFiltererWithIncludeAndSelect(AuthorFilterDto dto)
{
Func<IQueryable<Author>, IIncludableQueryable<Author, object>> include = a => a.Include(i => i.Books);
var entities = await _unitOfWork.Repository.GetSingleAsync<Author, AuthorFilterDto, object>(false, dto, select => new
{
SelectName = select.Name,
SelectDate = select.CreationDate
}, include);
return entity;
}
}
Welcome to the EasyRepository.EFCore
wiki!
Topics:
-
Getting Started
-
Implementations
-
Specification
-
Ardalis.Specification & EasyRepository.EFCore