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

假装没事ソ 提交于 2020-01-02 05:44:08

问题


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


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



来源:https://stackoverflow.com/questions/43548165/in-odata-is-there-a-way-to-order-by-the-first-element-in-an-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!