Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In OData, is there a way to order by the first element in an array?

Tags:

odata

odata-v4

I have an OData 4 endpoint I call for displaying data in a table. One of the columns has a set of data concatenated from a string array within my element. Is there a way to order by the first element in the array?

My element could look like this:

[ { "FirstName": "John", "MiddleNames": [ "Harry", "Bobby", "Sue" ], "LastName": "Jones" }, ... more elements ]

and I would like to order by MiddleNames[0].

Thanks for the help! The documentation on $orderby is sparse at best...

like image 730
Jereme Avatar asked Apr 21 '17 16:04

Jereme


People also ask

How do I filter OData query?

You can use filter expressions in OData requests to filter and return only those results that match the expressions specified. You do this by adding the $filter system query option to the end of the OData request.

What is odataquery?

The Open Data Protocol (OData) is a data access protocol built on core protocols like HTTP and commonly accepted methodologies like REST for the web. There are various kinds of libraries and tools can be used to consume OData services.

What is OData URI?

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.

What is OData type?

The odata. type annotation specifies the type of a JSON object or name/value pair. Its value is a URI that identifies the type of the property or object. For built-in primitive types the value is the unqualified name of the primitive type, specified as a URI fragment.


1 Answers

This is NOT supported in OData v4, the specification does not provide syntax for targeting specific items within a collection, or an array, for path expressions and $orderby is a path expression. It is however very explicit on the conditions that are supported, by omission this restriction is therefore by design.

5.1.1.15 Path Expressions
Properties and navigation properties of the entity type of the set of resources that are addressed by the request URL can be used as operands or function parameters, as shown in the preceding examples.

Properties of complex properties can be used via the same syntax as in resource paths, i.e. by specifying the name of a complex property, followed by a forward slash (/) and the name of a property of the complex property, and so on,

Properties and navigation properties of entities related with a target cardinality 0..1 or 1 can be used by specifying the navigation property, followed by a forward slash (/) and the name of a property of the related entity, and so on.

If a complex property is null, or no entity is related (in case of target cardinality 0..1), its value, and the values of its components, are treated as null.

like image 155
Chris Schaller Avatar answered Oct 26 '22 00:10

Chris Schaller