Nicaps
Nicaps

Reputation: 117

ODATA $expand and $select queries in url

Yes, I know, this question is always asked. But I looked for answers to my problem, and everything I've seen is the same explanation, but it still doesn't work for me. Explanations.

For example on the Northwind service (that I use to train because it is simple, before using my job's service) : https://services.odata.org/V2/Northwind/Northwind.svc/

If I do

It works.

BUT if I want to do : https://services.odata.org/V2/Northwind/Northwind.svc/Categories?$expand=Products($select=ProductName) (since there is a ProductName property in Products) ... It doesn't work. I have the error : Syntax error at position 9. That "position 9" corresponds to the first parenthesis.

However, all I have seen on http://odata.org/documentation and on StackOverflow's forum says it should be something like that. What do I wrong ?

Upvotes: 2

Views: 30406

Answers (2)

Nicaps
Nicaps

Reputation: 117

I found. In odata v2, we need to expand the entity we want to display and then select out of parenthesis with the path relative to the basis entity.

Example :

https://services.odata.org/V2/Northwind/Northwind.svc/Categories?$expand=Products&$select=Products/ProductName

It is not so weird after all...

Upvotes: 2

Vincent
Vincent

Reputation: 340

This is supported, you refer to an old sample service which is v2, you can do request like this one which is protocol v4 based, http://services.odata.org/V4/(S(ax34fkajuohvk1aw5pjzykjk))/TripPinServiceRW/People?$expand=Trips($select=TripId,Name)

It works well.

BTW, this sample service is built on some technology which is in maintained mode, if you start to build a new service, we will recommend to use RESTier, refer to odata.github.io/RESTier/ or use OData web Api library, refer to odata.github.io/WebApi

Upvotes: 3

Related Questions