AspNet.WebAPI.OData.ODataPQ
This is the query for paging under the ASP. NET WebAPI OData protocol. Or I'm using an extension library that is supported by a paging query service that I write when I use ASP. NET WebAPI as a service interface.
It supports paging operations by obtaining the total number of records under the MS ASP. NET WebAPI OData protocol.
In fact, paging is really simple, simple can not be simpler. The total number of pages, per page size. That's enough, but I can't find an example of how to get the total number of records under the ASP. NET WebAPI OData protocol
Or find an example, according to do N Times, is no, the total is not to return to me.
For the total number of records access to some information, such as $inlinecount =allpages, $count =true, has been a long time to toss.
Or just tell me: $inlinecount query parameters are not supported, or $count query parameters are not supported. It makes me uncomfortable. What a good OData, a total you give me, too irritating, really is (spit trough, O (∩_∩) o~).
Before I start using it, let me say a few words to AspNet.WebAPI.OData.ODataPQ.
AspNet.WebAPI.OData.ODataPQ, is the package name in the nuget.org, that is, the ID, the identification code, can be used when using the "Package Console Command Window" installation,
PM-Install-package AspNet.WebAPI.OData.ODataPQ [-version 5.2.2.1]
The extension library name is actually a file such as ODataPQ.dll.
There are currently 2 versions of NuGet. Respectively is (5.x, 4.x), the specific situation see below
5.2.2.1: The latest version (lasted version, with Publictokenkey)
5.2.2.0: Latest version (lasted version, no publictokenkey)
These two versions, is the difference one publictokenkey, the suggestion uses 5.2.2.1 this version.
If you are in the WEBAPI project. Microsoft.AspNet.WebApi.OData, which is the version of the System.Web.Http.OData assembly in the reference.
is 5.2.2.0 and above, it is recommended to use one of these two versions, do not use the following 4. x version of the Library
--------------------------------------------------------------------------------------------------------------- ---------------------------
4.0.30507: (for Assembly System.Web.Http.OData 4.0.30506 version has Publictokenkey)
4.0.30506: (for Assembly System.Web.Http.OData 4.0.30506 version without Publictokenkey)
These two versions, is the difference one publictokenkey, the suggestion uses 4.0.30507 this version.
If you have Microsoft.AspNet.WebApi.OData in your WEBAPI project, that is, the version of the System.Web.Http.OData assembly in the reference.
is 4.0.30506 and above, it is recommended to use one of these two versions, do not use the above 5. x version of the Library
--------------------------------------------------------------------------------------------------------------- --------------------------
OK, after the verbose, the following start to use it to achieve the simplest service (paged query, \ (^o^)/~)
The first step:
Creating an ASP. Webapi project, which is not much verbose (. net4.0,.net4.5 is available)
Step Two:
Confirm the version of your System.Web.Http.OData assembly, and if it is 4.0.30506, install ODATAPQ 4.0.30507/4.0.30506
"Package Management Console": PM--Install-package aspnet.webapi.odata.odatapq-version 4.0.30507
If System.Web.Http.OData is 5.2.2.0 and above, install ODATAPQ 5.2.2.1/5.2.2.0
"Package Management Console": PM--Install-package AspNet.WebAPI.OData.ODataPQ [-version 5.2.2.1]
Step Three:
Create a new controller, called Odatapqcontroller, inherited from Apicontroller. Add a Get action method to mark the method
Odata.odatapageresult. The Iqueryable<tentity> object is then returned. As follows.
With the above configuration, ODATAPQ's NuGet package installation and server-side code writing are done.
Fourth Step:
Query the parameters to see the client's effect. (Query parameters $filter, $top, $skip, and so on are consistent with the OData protocol.) The Data,total field is included in the returned data. This is what we need for paging. Total. )
More can refer to under Me (project source code already on Oschina open source) another article 拙笔.
Http://www.cnblogs.com/guizhouhehai/p/4524941.html
AspNet.WebAPI.OData.ODataPQ implementation of WebAPI paging query service-(personal 拙笔)