Search code examples
restwcf-data-servicesodata

Exposing children navigation properties in parent


Is it possible to expose, with OData, the children navigation properties in their parent entity ?

Assuming we have the following model:

http://yuml.me/e0a3284c

View model image also here

I want to have access to the list of all Vehicles with the category property loaded.

I tried /Vehicles/?$expand=category but the service don't recognize the property.

Thanks for your help.


Solution

  • You should try,

    /Vehicles?$expand=NS.Motorcycle/Category,NS.Car/Category

    NS would be the namespace of the Motorcycle and Car types respectively.

    You can expand properties that are present on the type that you are trying to expand which in this case is Vehicle. If you want to expand a navigation property present in a derived type, you have to first do a cast and then expand.