-
Notifications
You must be signed in to change notification settings - Fork 14
Filter Operations
Furkan Güngör edited this page Dec 3, 2021
·
3 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 IRepository repository;
public MyClass(IRepository repository)
{
this.repository = repository;
}
public async Task<List<Author>> ClassicWhere()
{
var entity = await repository.GetMultipleAsync<Author>(false, whereExpression: a => a.IsDeleted == false);
// or
var entity2 = await repository.GetMultipleAsync<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 IRepository repository;
public MyClass(IRepository repository)
{
this.repository = repository;
}
public async Task<List<Author>> AutoFilterer(AuthorFilterDto dto)
{
var entities = await repository.GetMultipleAsync<Author, AuthorFilterDto>(asNoTracking: false, dto);
return entities;
}
}
public class MyClass
{
private readonly IRepository repository;
public MyClass(IRepository repository)
{
this.repository = repository;
}
public async Task<List<Author>> AutoFiltererWithInclude(AuthorFilterDto dto)
{
Func<IQueryable<Author>, IIncludableQueryable<Author, object>> include = a => a.Include(i => i.Books);
var entity = await repository.GetMultipleAsync<Author, AuthorFilterDto>(asNoTracking: false, dto, includeExpression: include);
return entity;
}
}
public class MyClass
{
private readonly IRepository repository;
public MyClass(IRepository repository)
{
this.repository = repository;
}
public async Task<List<object>> AutoFiltererWithSelect(AuthorFilterDto dto)
{
var entity = await repository.GetMultipleAsync<Author, AuthorFilterDto, object>(asNoTracking: false, dto, select => new
{
SelectName = select.Name,
SelectDate = select.CreationDate
});
return entity;
}
}
public class MyClass
{
private readonly IRepository repository;
public MyClass(IRepository repository)
{
this.repository = repository;
}
public async Task<List<object>> AutoFiltererWithIncludeAndSelect(AuthorFilterDto dto)
{
Func<IQueryable<Author>, IIncludableQueryable<Author, object>> include = a => a.Include(i => i.Books);
var entities = await repository.GetMultipleAsync<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