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.
OData query option $expand is used to read multiple entities or entity sets in a single service call instead of two different calls. Prerequisite, entity sets which are used should be associated. To know about Association in OData service click here.
The Open Data Protocol (OData) is a data access protocol for the web. OData provides a uniform way to query and manipulate data sets through CRUD operations (create, read, update, and delete). ASP.NET Web API supports both v3 and v4 of the protocol.
The $value option is used to get individual properties of an Entity. There are two ways to get individual properties from an entity. We can get the response in either OData format or get the raw value of the property. We need to add method to the controller named GetProperty here property is a name of the property.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With