odata

OData v4 multiple level $expand


I'm trying to figure out how multiple level $expand option with "path" expand item is working.

I understand that the following request returns expand Trips from Russel's friends. http://services.odata.org/v4/TripPinServiceRW/People('russellwhyte')?$expand=Friends($expand=Trips)

http://services.odata.org/v4/TripPinServiceRW/People('russellwhyte')?$expand=Friends/Trips returns the following exception

"Found a path traversing multiple navigation properties. Please rephrase the query such that each expand path contains only type segments and navigation properties."

Looking the spec I notice the following :

An arbitrary number of single- or collection-valued complex properties, optionally followed by a type cast, allow drilling into complex properties.

So, I assume that "path" expand item are only working to expand complex property of a navigation entity. Is that correct? In this case why is the following request returning the same exception?

http://services.odata.org/v4/TripPinServiceRW/People('russellwhyte')?$expand=Friends/AdressInfo


Solution

  • From the Spec as you mentioned:

    expandPath = [ ( qualifiedEntityTypeName / qualifiedComplexTypeName ) "/" ] *( ( complexProperty / complexColProperty ) "/" [ qualifiedComplexTypeName "/" ] ) navigationProperty [ "/" qualifiedEntityTypeName ]

    From OData lib, it treats a path as expand path if it meets:

    1. there's only one navigation property and it should be the last segment if on other entity type cast segment after it.
    2. Before the navigation property, all other segments must be type cast segments or complex type property segment.

    Based on it, $expand=Friends/Trips is not valid navigation path, since it contains two navigation properties (Friends and Trips are both nav properties).

    So does '$expand=Friends/AdressInfo', since the last segment is non-navigation property. you should use $expand=Friends($select=AdressInfo)