Reputation: 21
I want to fetch as much as possible of nested data in one go for a given OData api (v4). However, I seem to be unable to expand navigation properties of all derived types together with all the other objects in different navigation properties.
As an example, there is the TripPin OData v4 sample service: https://services.odata.org/V4/(S(xjqbds2oavibr01gt1fny24s))/TripPinServiceRW/
There I want to fetch as much as I can about people: https://services.odata.org/V4/(S(xjqbds2oavibr01gt1fny24s))/TripPinServiceRW/People?$expand=Trips($expand=PlanItems) This will show me among others the PlanItems of the Trips of the People available in the api:
...,
PlanItems: [
...,
{
@odata.type: "#Microsoft.OData.SampleService.Models.TripPin.Flight",
PlanItemId: 13,
ConfirmationCode: "JH38143",
StartsAt: "2014-01-04T17:55:00Z",
EndsAt: "2014-01-04T20:45:00Z",
Duration: "PT0S",
SeatNumber: null,
FlightNumber: "AA4035"
},
{
@odata.type: "#Microsoft.OData.SampleService.Models.TripPin.Event",
PlanItemId: 12,
ConfirmationCode: "4372899DD",
StartsAt: "2014-01-02T13:00:00Z",
EndsAt: "2014-01-02T16:00:00Z",
Duration: "PT3H",
Description: "Client Meeting",
OccursAt: {
Address: "100 Church Street, 8th Floor, Manhattan, 10007",
City: {
CountryRegion: "United States",
Name: "New York City",
Region: "New York"
},
BuildingInfo: "Regus Business Center"
}
},
...
PlanItems contain objects of different derived types, i.e. Flight and Event. Flight has 3 other navigation properties as described in the metadata (https://services.odata.org/V4/(S(xjqbds2oavibr01gt1fny24s))/TripPinServiceRW/$metadata): From, To and Airline. I would like to fetch them together with all the other information. But I cannot figure out how, if possible.
It is possible to fetch them separately https://services.odata.org/V4/(S(xjqbds2oavibr01gt1fny24s))/TripPinServiceRW/People('russellwhyte')/Trips(0)/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight?$expand=Airline but that's not what I'm looking for.
Upvotes: 1
Views: 734
Reputation: 21
So I found the solution, it requires you first to start with a cast in order to use properties and navigation properties that are only defined on the derived type:
The clues I needed to figure this out, I found by going through the questions that had been posted in the OData Discussion google group.
Upvotes: 1