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.
OData expand functionality can be used to query related data. For example, to get the Course data for each Enrollment entity, include ?$ expand=course at the end of the request path: This tutorial uses Postman to test the web API.
The Open Data Protocol (OData) is a data access protocol built on core protocols like HTTP and commonly accepted methodologies like REST for the web. There are various kinds of libraries and tools can be used to consume OData services.
The $select option specifies a subset of properties to include in the response body. For example, to get only the name and price of each product, use the following query: Console Copy. GET http://localhost/odata/Products?$select=Price,Name.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With