AutoFilterer is a mini filtering framework library for dotnet. The main purpose of the library is to generate LINQ expressions for Entities over DTOs automatically. The first aim is to be compatible with Open API 3.0 Specifications
This feature aims to generate an expression for .Select() Linq method.
Declaration
See usage example for better understanding:
Entity
public class Book
{
public string Name { get; set; }
public int TotalPage { get; set; }
public DateTime CreateDate { get; set; }
public virtual ICollection<BookOrder> BookOrders { get; set; }
}
FilterDto (As always but inherits SelectorFilterBase)
public class BookFilterDto : SelectorFilterBase<BookDto>
{
[ToLowerContainsComparison]
public string Name { get; set; }
public Range<int> TotalPage { get; set; }
public Range<DateTime> CreateDate { get; set; }
}
Output dto:
public class BookDto
{
[From("Name")]
public string Title { get; set; }
public int TotalPage { get; set; }
public DateTime CreateDate { get; set; }
[Count("BookOrders")]
public int SellCount { get; set; }
[Sum("BookOrders.Price")]
public float TotalSoldPrice { get; set; }
}
Usage
As default, SelectorFilterBase should override ApplyFilter() method, so calling ApplyFilter method will work.
[HttpGet]
public IActionResult GetBooks([FromQuery] BookFilterDto filter)
{
var query = db.Books.ApplyFilter(filter); // IQueryable<BookDto>
return Ok(query.ToList());
}
Or alternative usage:
As default, SelectorFilterBase should override ApplyFilter() method, so calling ApplyFilter method will work.
[HttpGet]
public IActionResult GetBooks([FromQuery] BookFilterDto filter)
{
var query = db.Books.ApplySelector(filter) // IQueryable<BookDto>
.Where(x => x.TotalSoldPrice > 299.95); // If db provider supports.
return Ok(query.ToList());
}
Structure
FilterBase
OrderableFilterBase
PaginationFilterBase
SelectorFilterBase
TODO List
[x] Extension methods for last user usage
[ ] SelectorFilterBase and SelectorPaginationFilterBase implementation.
Summary
This feature aims to generate an expression for
.Select()
Linq method.Declaration
See usage example for better understanding:
Entity
FilterDto (As always but inherits SelectorFilterBase)
Output dto:
Usage
As default,
SelectorFilterBase
should overrideApplyFilter()
method, so calling ApplyFilter method will work.As default,
SelectorFilterBase
should overrideApplyFilter()
method, so calling ApplyFilter method will work.Structure
TODO List