5
votes

I currently have an OData V4 service that has the following model.
"Category" -- "Codes"
For each category there can be many codes.

I need to $expand the Codes, $filter where Active = true and then $orderby Codes.Description.

Currently the following works fine without ordering.

odata/Categories?$expand=Codes($filter=Active eq true)

This does not work.

odata/Categories?$expand=Codes($filter=Active eq true&$orderby=Description)

I receive "The query specified in the URI is not valid. Syntax error at position 12." & "Syntax error at position 12 in 'Description)'."

Basically it is reading the last ")" after "Description" as an error.

2

2 Answers

6
votes

I was not able to find this in the OData V4 documents but I did find a similar example here "How can I order objects according to some attribute of the child in OData?"

http://services.odata.org/V4/Northwind/Northwind.svc/Orders?$select=OrderID&$expand=Order_Details($select=UnitPrice;$orderby=Quantity)

The key I was missing is

;

This goes between the filter and orderby.
Here is the working url

odata/Categories?$expand=Codes($filter=Active eq true;$orderby=Description)

0
votes

OData V4 grouping last records get your service

odata/Categories?$expand=Codes($top=1;$orderby=Description)