Dynamic filtering extensions for IQueryable
that allows API clients to specify
OData $filter
, $orderby
, $skip
, $top
query string filter parameters without bringing the whole OData library to the mix.
[HttpGet]
public IActionResult Index(Query query)
{
return Ok(_dbContext.Users.ApplyQuery(query).ToList());
}
Giving "?$skip=1&$top=2&$filter=startswith(Name, 'j') or year(birthdate) ge 1970&$orderby=id desc"
will filter a list of actors down to this subset:
[
{
"id": 7,
"name": "Charlize Theron",
"birthDate": "1986-01-01T00:00:00"
},
{
"id": 6,
"name": "Jennifer Lawrence",
"birthDate": "1975-01-01T00:00:00"
}
]
$orderby
parameter does not support multiple orders (first name, then date etc.). At the moment only a single ordering is possible.
This library is created thanks to a great guide by Evgeny Bychkov and StringToExpression library