I am wondering would anyone be able to help me. I am trying implement custom paging into a OData feed (oData v4). I am filling the IEnumerable from a stored procedure to which I have added a means of paging by below (Working Perfect)
SELECT * FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY OrderID ) AS RowNum, * FROM dbo.Order WHERE CompanyID = @CompanyID ) AS RowConstrainedResult WHERE RowNum >= @Start AND RowNum <= @Finish ORDER BY RowNum However the issue I am having is that the below code works perfect apart from the paging is not working
[EnableQuery] public async Task<PageResult<Order>> GetOrders(ODataQueryOptions<Order> queryOptions) { int CompanyID = User.Identity.GetCompanyID().TryParseInt(0); ODataQuerySettings settings = new ODataQuerySettings() { PageSize = 100, }; int OrderCount = _OrderRepo.GetOrderCount(CompanyID); int Skip = 0; if (queryOptions.Skip != null) { Skip = queryOptions.Skip.Value; } IEnumerable<Order> results = await _OrderRepo.GetAll(CompanyID, Skip, 100); IQueryable result = queryOptions.ApplyTo(results.AsQueryable(), settings); Uri uri = Request.ODataProperties().NextLink; Request.ODataProperties().TotalCount = OrderCount; PageResult<Order> response = new PageResult<Order>( result as IEnumerable<Order>, uri, Request.ODataProperties().TotalCount); return response; } Basically I am trying to page through the results in batches of 100, taking 100 at time from the database only as needed.
When I first call that controller I get the expected results.
http://localhost:24600/Data/Orders But when I query this nextLink (below), I get no errors but no results despite the fact there is over 50,000 results in the database and the IEnumerable results has been updated correctly.
http://localhost:24600/Data/Orders?$skip=100 I would be extremely gratefully if someone help me out with this as I am new to using odata.
Update
It looks like, it is counting the size of the first batch and taking that as the total size, even though I am setting the total size. It seems to not be able to go above the initial size.