Contact Manager web API example [3] Paging and querying)

Source: Internet
Author: User
Tags sorted by name

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.