I'm trying to order by nested collection filtered count and couldn't figure out how to do it in OData.
I will use public OData API (from Microsoft) for demo to explain what I mean, no need for authorization
https://services.odata.org/TripPinRESTierService/
So we have People there
https://services.odata.org/TripPinRESTierService/People
These People have Trips
https://services.odata.org/TripPinRESTierService/People?$expand=Trips
If I want to filter Trips by Name, it's easy
https://services.odata.org/TripPinRESTierService/People?$expand=Trips($filter=Name eq 'Trip in Beijing')
If I want to order People by Trip count, it's easy as well
https://services.odata.org/TripPinRESTierService/People?$expand=Trips($count=true)&$orderby=Trips/$count desc
But I'm not able to order by filtered count of trips (for case when $expand=Trips($filter=Name eq 'Trip in Beijing'))
https://services.odata.org/TripPinRESTierService/People?$expand=Trips($count=true;$filter=Name eq 'Trip in Beijing')&$orderby=Trips/$count desc
Something like &$orderby=Trips($filter=Name eq 'Trip in Beijing')/$count desc or &$orderby=Trips/$count($filter=Name eq 'Trip in Beijing') desc doesn't work (gives server error "Could not find a property named 'Name' on type 'Trippin.Person'.").
Version of this URL to see minimum required data
https://services.odata.org/TripPinRESTierService/People?$expand=Trips($top=0;$count=true;$filter=Name eq 'Trip in Beijing')&$orderby=Trips/$count desc&$select=Trips
Update: I'm using Microsoft.AspNetCore.OData version 7.5.7 in my project which depends on Microsoft.OData.Core version 7.7.3 (It's not installed explicitly). Probably if Microsoft will upgrade version of OData in its API it's going to work as well.