Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 316
TYRONEMICHAEL Avatar asked Nov 06 '14 15:11

TYRONEMICHAEL


People also ask

What is $expand in OData?

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.

What is OData in Web API with example?

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.

What is $value in OData?

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.


1 Answers

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)
like image 167
TYRONEMICHAEL Avatar answered Oct 03 '22 11:10

TYRONEMICHAEL