OData pagination with WebApi ( $inlinecount )

前端 未结 3 1991
情话喂你
情话喂你 2021-01-02 06:58

I am using OData to paginate a long list of items returned from a web api call. I can filter the data via the url with the start and end index.

The question I have i

3条回答
  •  清歌不尽
    2021-01-02 07:21

    I had the exact issue last week. Check out Extending your ASP.NET Web API responses with useful metadata

    I used this post and sample code to get a paging grid up and running using OData. As detailed in the sample I created a delegating handler to capture the HttpResponseMessage and wrap it in custom metadata that includes an item count. A custom attribute, CustomQueryableAttribute, is also created that inherits the default QueryableAttribute.

    It may sound a little complex here but is actually pretty simple to implement. I had something up and running in about 30 minutes.

    Hopefully future versions of the Web API have more complete OData support.

    EDIT: Odata support will NOT be shipping with the Web API. The queryable attribute is being removed for the RTM release. More complete OData support will be available sometime after the initial relase via a separate Nuget package.

提交回复
热议问题