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

1

7

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...

Bixler answered 21/4, 2017 at 16:53 Comment(0)
S
1

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.

Salley answered 20/12, 2019 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.