OData v4 $filter exclude empty array from result

If you want to filter out empty results you can end with $filter=Product/Categories/any()

I had to query out some nested properties via Odata v4 and it was up to 140k results without a proper filter.

I have a List of Products that each contains a List of Categories.

If I just query like Product($select=Id;$expand=Categories($select=Id,Name)) I would get 140k results.

Some products have an array of categories and some doesn’t. So I can filter out those that has at least one category by typing

Product($select=Id;$expand=Categories($select=Id,Name)$filter=Product/Categories/any())

Now i’ve gotten the result down to 4k instead of 140k just by the the last part where we check if categories has anything with $filter=Product/Categories/any()

Leave a comment