Reputation:
Is there Any method out there to query actual EF database through API parameters?
We know OData Query allows for querying the Final result API. Is it possible to use IQueryable to have simple SQL EF queries sent from OData Query Api layer?
We want to apply Pagination, and instead of extracting All 1000 records, let some API layer, query the results only needed (say, results 5-10 only), etc. This may not be best practice all the time, just need option to exist for certain cases.
/api/Product?$skip=5&$top=5
/api/persons?$orderby=name
/api/persons?$select=ID,Name
/api/students?$filter=Name eq ‘Todd’
Upvotes: 2
Views: 561
Reputation: 720
The parameters $skip and $top do exist in OData and should work if you perform these on an IQueryable.
For instance, calling the following URL:
http://localhost:24367/TestData?$skip=5&$top=5
would skip the first 5 records and take the next 5 records.
Your MVC action (if you're MVC that is) would look like this:
[EnableQuery]
public IHttpActionResult Get()
{
var result = GetData().AsQueryable();
return Ok(result);
}
More information can be found in this excellent post: https://www.c-sharpcorner.com/article/paging-with-odata-and-Asp-Net-web-api/
Upvotes: 2