Skip to content

Instantly share code, notes, and snippets.

@craigcabrey
Created November 19, 2015 17:31
Show Gist options
  • Save craigcabrey/52a6f7bfc7aaf15810f6 to your computer and use it in GitHub Desktop.
Save craigcabrey/52a6f7bfc7aaf15810f6 to your computer and use it in GitHub Desktop.
OData Paging
// GET: /applications
[Route("")]
[HttpGet]
public PageResult<Application> Get(ODataQueryOptions<Application> options)
{
ODataQuerySettings settings = new ODataQuerySettings()
{
PageSize = 5
};
IQueryable results = options.ApplyTo(_db.Applications.AsQueryable(), settings);
return new PageResult<Application>(
results as IQueryable<Application>,
options.Request.ODataProperties().NextLink,
options.Request.ODataProperties().TotalCount
);
}
@craigcabrey
Copy link
Author

Must include the query parameter $count=true for the Count field to be populated by OData.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment