The contact Manager web API is an Asp.net web API example program that demonstrates how to publish contact information through ASP. NET web API and allows you to add and delete contacts. The example address is http://code.msdn.microsoft.com/contact-manager-web-api-0e8e373d.
Contact Manager web API example [1] The CRUD operation has been introduced,
Contact Manager web API example [2] web API routing introduces web API routing.
This article describes how to query and paging odata.
Odata open data protocol is launched by Microsoft for Google's gdata. It aims to promote the standardized open data protocol for Web application database formats. Microsoft defines odata as a protocol based on HTTP, atompub, and JSON, enhance data compatibility between various web applications to provide information access to multiple applications, services, and data stores.
Specify open data protocal (odata)Query string ParametersAllows the client to use it to sort and filter results.
Web APIs provide the following odata query parameters:
Web APIs support odata query parameters |
Query Parameters |
Description |
Example |
$ Filter |
Select a project that matches the Boolean expression |
Http: // localhost: Port/API/contacts? $ Filter = substringof (name, 'ed') eq true |
$ Orderby |
Sort the result by the specified attribute. |
Http: // localhost: Port/API/contacts? $ Orderby = Name |
$ Skip |
Skip the first n elements |
Http: // localhost: Port/API/contacts? $ Skip = 2 |
$ Top |
Returns the first n elements. |
Http: // localhost: Port/API/contacts? $ Orderby = Name |
If $ top is used with $ orderby, It is sorted first, and then the first n elements are obtained to return.
For example, the following URI will return the first three pieces of contact data, sorted by name.
Http: // localhost: Port/API/contacts?$ Top = 3&Orderby = Name
To support these query options, simply go back from the get MethodIqueryable typeAnd queryable attribute (System. Web. http. queryableattribute).
. For example
[Queryable (resultlimit = 20)]
Public iqueryable <contact> get ()
{
Return this. repository. getall (). asqueryable ();
}
You only need the help of. asqueryable () to help us switch.
For more information about odata string parameters, see odata: URI conventions.
Reference data
· Paging and querying
· Http://www.odata.org/