OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

Filtering by count of a child collection #1661

Open Hasanchiver opened 4 years ago

Hasanchiver commented 4 years ago

I am having trouble writing a query for filtering by count of a child collection. I have two types of entities.

Assemblies affected

Microsoft.AspNetCore.OData 7.3.0

Reproduce steps

I have two types of entities: Orders and Suborders. Orders contain a list of Suborders. I want to query for an Order with exactly 2 Suborders or exactly 3 Suborders. How should I write my query? I haven't been able to find anything online for this within the past 24 hours.

xuzhg commented 4 years ago

Hi, Hasanchiver It seems you can use the query string like ~/Orders?$filter=SubOrders/$count eq 2. However, it's not supported yet in OData library, Neither for ASP.NET Core OData. There's a PR #1336 related to this feature which is under reviewing. Once that PR get merged, we can work this feature in ASP.NET Core.

cc5zhenhua commented 3 years ago

Any workaround?