I'm trying to do some custom sorting in OData using this URL
localhost:82/odata.svc/ComponentPresentations?$filter=TemplateId eq 2894 and publicationId eq 10&$expand=Component/Keywords?$orderby=Title desc
Where Component
is a property of ComponentPresentation
and Keywords
is property of Component
, and I want to sort the ComponentPresentation according to the keyword's Title
attribute. But keywords nor title is a property of Component Presentation
Is there a way to sort the results according to the attribute of Keword's title? Which is a Child of Component, which is a child of ComponentPresentation?
The $filter system query option allows clients to filter the set of resources that are addressed by a request URL. $filter specifies conditions that MUST be met by a resource for it to be returned in the set of matching resources. The semantics of $filter are covered in the OData:Core document.
You can find details on filter specification in the OData spec filter options section. Examples: All products with a Name equal to 'Milk': http://host/service/Products?$filter=Name eq 'Milk' All products with a Name not equal to 'Milk' : http://host/service/Products?$filter=Name ne 'Milk'
The OData Protocol is an application-level protocol for interacting with data via RESTful interfaces. It supports the description of data models, editing and querying of data according to those models.
Introduction. The Open Data Protocol (OData) enables the creation of REST-based data services, which allow resources, identified using Uniform Resource Identifiers (URIs) and defined in a data model, to be published and edited by Web clients using simple HTTP messages.
Just want to mention that it is possible since OData V4. You can nest as many expands/selects/orderby/filters as you wish. Now it is as simple as
http://services.odata.org/V4/Northwind/Northwind.svc/Orders?$select=OrderID&$expand=Order_Details($select=UnitPrice;$orderby=Quantity)
It is possible to sort the results by a nested single-cardinality property, for example: http://services.odata.org/V3/Northwind/Northwind.svc/Orders?$top=50&$expand=Customer&$orderby=Customer/City
AFAIK, it's not possible to do this with a navigation property that has a cardinality of many (though it would be useful in expand scenarios to order what comes back in the expanded feed).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With