简体   繁体   中英

Web Api 2.2 with odata and $expand

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM