Sorting by nested properties

Topics: ASP.NET Web API
Mar 21, 2013 at 10:34 PM
Hello,

my OData query contains this orderby clause: orderby=Priority.Name. When it is executed, it throws an ODataException: "Only ordering by properties at the root level is supported for non-primitive collections. Nested properties and expressions are not supported.".

Why is this not supported and when it will be supported? Are there any workarounds?

Thank you!

Dusan
Mar 21, 2013 at 10:54 PM
djanosik wrote:
Hello,

my OData query contains this orderby clause: orderby=Priority.Name. When it is executed, it throws an ODataException: "Only ordering by properties at the root level is supported for non-primitive collections. Nested properties and expressions are not supported.".

Why is this not supported and when it will be supported? Are there any workarounds?

Thank you!

Dusan
The reason for not supporting it is simple - time :). That said, the uri parser supports parsing complex $orderby queries. So, you don't have to deal with any parsing to implement support for nested properties. Check out how we implement $orderby support from this file - http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/a8e957f5b5f8#src/System.Web.Http.OData/OData/Query/OrderByQueryOption.cs

You can implement a custom OrderByOption and override ApplyTo. Grab the parsed OrderBy clause from the OrderByClause property and translate nested properties to expressions and apply them on top of IQueryable.
Oct 17, 2013 at 6:17 PM
Hi,

Two questions... First: Did the team already had time? :) Second: If not, can you elaborate more in how I can achieve this result?

Thanks,
Nuno
Coordinator
Oct 23, 2013 at 8:57 PM
Take a look at ODataQueryOptions. You can bind an action parameter to the ODataQueryOptions and then get your hands on the parsed abstract syntax tree for the query. You can then implement the query however you want.

Daniel Roth