Dynamics CRM 2015/2016 Web API: New ways to query data

Source: Internet
Author: User

Today we take a look at the Web API data query functionality, although the previous introduction of crud article mentioned how to read the data, but did not go into the details of the details, today we will come to concrete look at it. In fact, the WEB API's data query interface is also based on the OData protocol, so the previous OData URL query construction rules have not changed very much, for example: $top, $select, $filter, $expand, $order function is still in, But something new has been added, such as

$count--Returns the total number of records

Paging mechanism (paging mechanism)--come on, now, the implementation mechanism is different, set the page size based on the HTTP header

Formatted Value (new thing, no latest document found)--visual and record formatting, but no specific mapping document found


$count

$count well understood, returns the total number of records in the system (related to the filter condition), and returns the total number of all records if the filter condition is not established.



Paging mechanism need to set HTTP header: Odata.maxpagesize=? , not the same as the previous API.



 Httprequestmessage retrieveaccreq = new Httprequestmessage (httpmethod.get, Webapiurl + "/accounts? $select =name&$            Count=true ");            RetrieveAccReq.Headers.Authorization = new Authenticationheadervalue ("Bearer", Accesscode);            RETRIEVEACCREQ.HEADERS.ADD ("Prefer", "odata.maxpagesize=2"); String Nextpagelink = String.            Empty;            Jobject result = null;            int pageIndex = 1;            Httpresponsemessage Retrieveaccresp; do {if (!string). Isnullorwhitespace (Nextpagelink)) {retrieveaccreq = new Httprequestmessage (HTTPMETHOD.G                    ET, nextpagelink);                    RetrieveAccReq.Headers.Authorization = new Authenticationheadervalue ("Bearer", Accesscode);                RETRIEVEACCREQ.HEADERS.ADD ("Prefer", "odata.maxpagesize=2"); } RETRIEVEACCRESP = await client.                SendAsync (Retrieveaccreq); result = Jsonconvert.deserializeobject<joBject> (await RetrieveAccResp.Content.ReadAsStringAsync ());                Console.WriteLine ("page-" + pageindex++); Console.WriteLine (Result.                ToString ()); if (Retrieveaccresp.issuccessstatuscode) {if (result["@odata. NextLink"]! = NULL &AMP;&A MP;!string. Isnullorwhitespace (result["@odata. NextLink"]. Value<string> ())) {Nextpagelink = result["@odata. NextLink"].                    Value<string> ();                    } else {nextpagelink = "";                }} else {break; }} while (!string. IsNullOrEmpty (Nextpagelink));


formatted Value

Visual and return records of the formatting related to the returned records better understand, but did not find the specific formatted Mapping, recommended not easy to use.



Httprequestmessage retrieveaccwithformattedvaluereq = new Httprequestmessage (httpmethod.get, WebApiUrl + "/accounts?$            select=name,donotpostalmail,accountratingcode,numberofemployees,revenue& $top = 1 ");            RetrieveAccWithFormattedValueReq.Headers.Authorization = new Authenticationheadervalue ("Bearer", Accesscode); RETRIEVEACCWITHFORMATTEDVALUEREQ.HEADERS.ADD ("Prefer", "odata.include-annotations=\"            Odata.community.display.v1.formattedvalue\ ""); Httpresponsemessage Retrieveaccwithformatedvalueresp = await client.            SendAsync (Retrieveaccwithformattedvaluereq); if (retrieveaccwithformatedvalueresp.issuccessstatuscode) {jobject result = Jsonconvert.deseria                Lizeobject<jobject> (await RetrieveAccWithFormatedValueResp.Content.ReadAsStringAsync ()); Console.WriteLine (Result.            ToString ()); }

In the Web API data query inside, there is a more important thing is to use the Web API query Function, bo in the following blog post for you to introduce its use.




Dynamics CRM 2015/2016 Web API: New ways to query data

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.