18

I am using codefirst with odata. I have setup my models and with relationships. The query seems to be working successfully. I am only running in an issue when using $expand when expanding nested data. I followed the following link off Microsoft's website. So I can do the following successfully

http://myurl.com/odata/catagories?$expand=Product

Now If i decide to go a level deeper usinng the following query

http://myurl.com/odata/catagories?$expand=Product/Supplier

I get the following error

The query specified in the URI is not valid. Found a path traversing multiple navigation properties. Please rephrase the query such that each expand path contains only type segments and navigation properties.

If you visit the link above, someone in the comments seems to be having the same issue. I could swear I got this to work with a previous version of odata and Web Api.

TYRONEMICHAEL
  • 4,174
  • 4
  • 30
  • 47

1 Answers1

38

I found the answer after finding this question. @Rama provided the answer. I suggest Microsoft updates their docs on the link listed above. So instead of

http://myurl.com/odata/catagories?$expand=Product/Supplier

You would rather use

http://myurl.com/odata/catagories?$expand=Product($expand=Supplier)
Community
  • 1
  • 1
TYRONEMICHAEL
  • 4,174
  • 4
  • 30
  • 47
  • 2
    The formal syntax is for OData V3, but later is for V4 – Karata Nov 07 '14 at 15:00
  • 3
    the slash notation is odata v4: http://docs.oasis-open.org/odata/odata/v4.0/errata01/os/complete/part2-url-conventions/odata-v4.0-errata01-os-part2-url-conventions-complete.html#_Toc395267179 – Jerther Feb 12 '15 at 21:10
  • 2
    Particularly bad, because Microsoft claims it's implementing OData v4, and OData4 clients libraries will make the request using the Slash method. Rather than update the docs, Microsoft should update their implementation of Nested Expand. – Jamie Butler May 16 '16 at 02:13
  • @JamieButler That is not the case. According to the standard, the slash syntax is only used for complex types (types without keys), which Microsofts implementation supports. – lauxjpn Sep 15 '20 at 05:29