OData V4 $expand nested $filter and $orderby -- combine $filter and $orderby inside expand
Asked Answered
B

2

6

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.

Billon answered 18/10, 2016 at 0:41 Comment(0)
B
7

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)

Billon answered 18/10, 2016 at 16:51 Comment(0)
J
0

OData V4 grouping last records get your service

odata/Categories?$expand=Codes($top=1;$orderby=Description)
Jacquez answered 13/8, 2020 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.