Using microsoft.aspnet.odata 5.10.0 (But I haven't found a solution in test projects using Microsoft.AspNet.OData 7.5.15 either)
I have an OData API that performs manual querying - we don't use IQueryable and instead do server-side paging manually. (We can't use something like EF to do this automatically)
Our code looks similar to this sample in that we use PageResult, except that we set the Total/NextLink like this:
this.Request.ODataProperties().TotalCount = pagedResult.Count;
this.Request.ODataProperties().NextLink = pagedResult.NextPageLink;
What we are looking for is similar to this question on github, which is attempting to set a different page size for a nested collection, compared to the root collection.
Taking the example from the spec, we would like to manually set Orders@odata.nextLink
{
"@odata.context": "http://host/service/$metadata#Customers/$entity",
...
"Orders@odata.count": 42,
"Orders": [ ... ],
"Orders@odata.nextLink": "...",
...
}
ODataProperties() doesn't work for nested Collections, it only applies to the outer value.
The odata serializer won't let you name a property with @odata in it, so we can't just make a new property on our model and name it Orders@odata.nextLink via an attribute.
ITruncatedCollection/TruncatedCollection is the way to solve this - it exists in both versions too. You can use it anywhere you need an IList. You can set the page size on the server and if the size of the underlying collection is larger than the page size the odata library will generate a next link + property.