Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
25 views16 pages

Query Options Usage

The document provides an overview of various OData query options, including $filter, $select, $count, $top, and $skip, which allow clients to manipulate and retrieve specific data from collections. Examples illustrate how to filter resources based on properties, select specific fields, count items, and paginate results. The document emphasizes the use of JSON payloads for responses and includes sample requests for better understanding.

Uploaded by

asfranco805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
25 views16 pages

Query Options Usage

The document provides an overview of various OData query options, including $filter, $select, $count, $top, and $skip, which allow clients to manipulate and retrieve specific data from collections. Examples illustrate how to filter resources based on properties, select specific fields, count items, and paginate results. The document emphasizes the use of JSON payloads for responses and includes sample requests for better understanding.

Uploaded by

asfranco805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 16
126025, 8:07 AM Query options usage - OData | Microsoft Learn Query options usage Article + 12/08/2022 Filter The $#ilter system query option allows clients to filter a collection of resources that are addressed by a request URL. The expression specified with $filter is evaluated for each resource in the collection, and only items where the expression evaluates to true are included in the response. Basic predicates, built-in functions There are several kinds of basic predicates and built-in functions for $¢i1ter, including logical operators and arithmetic operators. For more detailed information, please refer to OData V4 URL Conventions Document. The request below using $filter to get people with FirstName "Scott". GeT serviceroot/People?$filter-FirstNane eq "Scott! Response Payload JSON @odata. context": "serviceRoot/$metadatatiPeople", value": [ “serviceRoot/People(‘scottketchun")”, “w/"@ani6s4c7ES10464"", 2 "serviceRoot/People(‘scottketchum’)", "scottketchum", 'scott” "Emails": [ ‘cott@example. con L ‘AddressInfi { C "Address": "2817 Milton Dr.", ncaty": { “CountryRegion": "United States", ‘Albuquerque” titpseam microsoft comlen-uslodatalconceptsiqueryopions-usage ane. 3126025, 8:07 AM Query options usage - OData | Microsoft Learn LL "Gender": "Male", "Concurrency": 635404799693620400 Filter on Complex Type $filter can also work on complex type. The request below returns airports with "San Francisco" contained in its Address. And Address is property of complex type Location. cet serviceRoot/Airports?$filter-contains(Location/Address, ‘San Francisco") Response Payload JSON scontext": “serviceRoot/$metadatatAirports", Pt “@odata.id": "serviceRoot/Airports(‘KSFO")", @odata.editLink": "serviceRoot/Airports('KSFO')", "Icaocode": "KSFO", Name": "San Francisco International Airport", TataCode": "SFO", “Location” "Address South McDonnell Road, San Francisco, CA 94128", California" "coordinates": [ -122.374722222222, 37.6188888888889 titpseam microsoft comlen-uslodatalconceptsiqueryopions-usage ane 3128125, 8:07 AM ‘Query options usage - ODsta | Merosoft Learn Filter on Enum Properties The request below returns all female People of entity type Person. The Gender is a property of Enum ty GET serviceRoot/People?$filter=Gender eq Microsoft .oData.SanpleService.Models.TripPin.PersonGender'Fenale" Response Payload JSON "@odata.context": "serviceRoot/$metadata#People", “@odata.nextLink": “serviceRoot/People? %24Filter=Gender-+eq+Microsoft .OData .SampleService Models. TripPin.PersonGenderX2 ‘7Female%278&%24skiptoken: "value": [ { “@odata. id” “@odata.etag’ “@odata.editLink “elainestewart™, serviceRoot/People('elainestewart')", 'W/"@8D1694CCFB34453"", “LastName”: “Stewart, "emails": [ "[email protected]", “Elaine@contoso. com" 1 “Addressinfo": [], "Gender": “Female, "Concurrency": 635404801059013800 “@odata.id": “serviceRoot/People( ‘ursulabright')", “@odata.etag": "W/"@8D1694CCFB34453"", “@odata.editLink": "serviceRoot/People( ‘ursulabright')", “UserName”: “ursulabright", “FirstName”: “Ursul: “LastName”: “Bright” "Emails": [ “[email protected]", intpssn 1. microsoft. com/un.uslodatafconceptsiqueryoptions-usage "serviceRoot/People( ‘elainestewart')", 36 3126025, 8:07 AM Query options usage - OData | Microsoft Learn “[email protected]" Nested Filter in Expand OData V4 supports nested filters in expand. The request below return People and all their trips with Name "Trip in US". GET serviceRoot/People?$expand=Trips($Filter-Nane eq ‘Trip in us’) Response Payload JSON @odata.context": “serviceRoot/$metadataiPeople", @odata.nextLink": “serviceRoot/People? %2sexpand=Trips (%24Fi lter%3dNameveq%27Trip+intUS%27 )&X2Askiptoken=8" , [ ‘value’ { “serviceRoot/People( 'russelluhyte')", 'w/"@8D1694D@DBBD9DB"", erviceRoot/People( 'russellwhyte') @odata. i @odata.etag”: @odata.editLink “russellwhyte”, ‘UserName FirstName": "Russell", “LastName”: "Whyte", "Emails": [ "Russel [email protected]" "Russel l@contoso. com" "Address": "187 Suffolk Ln.", "city": { "CountryRegion": "United States", Boise", “ID! ? ? 1, "Gender": "Male", "Concurrency": 635404802@99763700, titpseam microsoft comlen-uslodatalconceptsiqueryopions-usage ane 3128125, 8:07 AM ‘Query options usage - ODsta | Merosoft Learn “Trips@odata. context”: “serviceRoot/$metadata#People(‘russellwhyte’ )/Trips" , "Trips": [ t “Triprd": 1002, "shareId": "9d9b2Fa0-efbf-490e-a5e3-bac8f7447354",, "Description": “Trip from San Francisco to New York City", "Name": "Trip in US", "Budget": 3000, "Startsat": "2014-01-01T00:00:002", "EndsAt": "2014-01-04700:00:002", "Tags": [ “business”, “New York meeting” “@odata.id": "serviceRoot/People( ‘keithpinckney' ) “@odata.etag": "W/"@8D1694D@DBBD9DB"" , "@odata.editLink": "serviceRoot/People('keithpinckney")", "UserName": “keithpinckney", “FirstName”: "Keith" “LastName”: "Pinckney", "Emails": [ "Keith@example. con ‘eith@contoso. cor 1 “addressinfo” "Gender": "Male", “concurrency”: 635404802099763700, “Trips@odata. context” : “serviceRoot/$metadatatPeople( ‘keithpinckney")/Trips”, “Trips”: (] O. + Select The $select system query option allows the clients to requests a limited set of properties for each entity or complex type. The request below returns Name and IcaoCode of all Airports. -ntps:Near, mlerosoftconvan-usladatalconcaptsiqueryoptons-usage one 126025, 8:07 AM Query options usage - OData | Microsoft Learn GET serviceRoot/Airports?$select=Name, Icaocode Response Payload JSON { “@odata.context": "serviceRoot/$metadata#Airports (Name, IcaoCode)", "value": [ { “@odata.id": “serviceRoot/Airports(‘KSFO")", “@odata.editLink": “serviceRoot/Airports(‘KSFO")", “Name": "San Francisco International Airport", “IcaoCode": "KSFO" ny { “@odata.id": "serviceRoot/Airports('KIFK')", ‘@odata.editLink": "serviceRoot/Airports(‘KIFK')", : "John F. Kennedy International Airport”, "Teaocode": "K3FK" + ] } Count The $count system query option allows clients to request a count of the matching resources included with the resources in the response, The request below returns the total number of people in the collection. GET serviceRoot/People?$count=true Response Payload JSON 20 System Query Option $count titpsleam microsoft comen-usfodatalconceptsiqueryopions-usage ene s28ns, 807 AM ery options usage - Daa | Most Learn The $count system query option allows clients to request a count of the matching resources included with the resources in the response. The request below returns the total number of people in the collection. GET serviceRoot/People?$count=true Response Payload JSON 20 Top & Skip System Query Option $top and $skip The $top system query option requests the number of items in the queried collection to be included in the result, The $skip query option requests the number of items in the queried collection that are to be skipped and not included in the result. The request below returns the first two people of the People entity set. GET serviceRoot /People?$top=2 Response Payload JSON -contex oo serviceRoot/$metadatatPeople", “@odata.id": “serviceRoot/People(‘russellwhyte")", “@odata.etag": "W/"@8D1694D4AA4A801" @odata.editLink": "serviceRoot/People( ‘russelIwhyte')", "UserName": “russellwhyte", “FirstName”: "Russell", "LastName": “Whyte”, "Emails": [ "[email protected]", "[email protected]" titpseam microsoft comlen-uslodatalconceptsiqueryopions-usage me 3128125, 8:07 AM ‘Query options usage - ODsta | Merosoft Learn ‘Address’ city": { “CountryRegion "Name": "Boise", "Region": "ID" "187 Suffolk Ln.", “United states", "W/"@8D1694D4AA4A801"", @odata.editLink": "serviceRoot/People('scottketchum')", "UserName": "scottketchum", 1 "Scott" “FirstName LastName": "emails": [ "[email protected]” 1, “AddressInf t ae "address" : "city": { “CountryRegion": "United States", "Name": “Albuquerque”, "Region: "NM" "2817 Milton Or.", ? L Gender": “Male”, "Concurrency": 635404803121654000 The request below returns people starting with the 19th people of the entity set People GET serviceRoot/People?$skip=18 Response Payload JSON "@odata.context": serviceRoot/$metadatatPeople", intossn ane

You might also like