0
votes

I've had no luck getting paging to work. What I'm seeing is that the Odata layer is skipping the data that the controller is returning (i.e. I want to control paging and filtering server-side). If I make a request without $skip= then the API returns 10 records. If I set $skip=100, 0 records are returned. Any suggestions? Controller method below:

[EnableQuery(PageSize=10)]      
public IHttpActionResult GetProducts(ODataQueryOptions<Product>  
queryOptions)
{    
List<Product> results = new List<Product>();
for (int i = 0; i < 10; i++)
{
    results.Add(new Product() { Id = Guid.NewGuid(), Name=  
    "Product"+ i.ToString() });
}
Request.ODataProperties().NextLink =  
    newUri(getNextUrl(queryOptions.Skip,10));
return Ok<IQueryable<Product>>(results.AsQueryable());
}
1

1 Answers

0
votes

when there is a $skip and pagesize set in server side. The logic is skip should apply first, and then return the pagesize of the result. For example: you return 100 orders in the /Orders API, I use $skip=5, then client should get the 95 orders, skip the first 5 orders, then if you set pagesize is 10, client should get the 5 - 15, 10 orders. So in your scenario, you already done the paging work in controller logic, OData apply skip after your paging, so result is wrong, it's like we only have 10 products, and request skip 10, so result is empty.