7
votes

I have a OData service with WebAPI OData 6.0.0, and it supports queries like this:

/Customers?$expand=Projects($count=true)

This will return a list of Customers with all the Projects underneath each Customer with the count of those projects in addition for each.

What I now would like to have is a query that will get the list of customers, and for each customer ONLY the count of its projects, not the list of projects.

Is there a way to create such a query?

I tried

/Customers?$select=Name,Projects/$count

but this is not working.

1

1 Answers

11
votes

You can kind of accomplish this by using $expand with $top option. It will output Projects as an empty collection.

/Customers?$select=Name&$expand=Projects($count=true;$top=0)