Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData select query not working in ASP.NET WebAPI beta

I'm playing around with the WebAPI beta, and it seems that selects have no effect on the response of an action returning an IQueryable. Eg:

http://localhost:62689/api/product?$select=Id,Name

Expected:

<Product>
<Id>1</Id>
<Name>Product 1</Name>
</Product>

Actual result:

<Product>
<Id>1</Id>
<Name>Product 1</Name>
<ItemsInStock>6</ItemsInStock>
<Price>49.99</Price>
<Created>2012-01-15T00:00:00</Created>
</Product>

Are there limitations on OData support for WebAPI?

I've tried other queries on this set of data (like top, filter) and they work fine.

like image 697
Sir Code-A-Lot Avatar asked Mar 01 '12 10:03

Sir Code-A-Lot


People also ask

How do I enable OData in Web API?

In Solution Explorer, right click on Models folder > Add > Class > Name your class. Now, we are going to create a Controller. Right click on the Controllers folder > Add > Controller> selecting Web API 2 OData v3 Controller with actions, using Entity Framework > click Add.

Which OData query option does Web API support?

The following are the OData query options that ASP.NET WebAPI supports, $orderby: Sorts the fetched record in particular order like ascending or descending. $select: Selects the columns or properties in the result set.


1 Answers

The Web API does not support the OData $select query.

The current support of query string parameters is limited to $top, $skip, $filter and $orderby.

Take a look at this forum post for more details.

like image 136
Szilard Muzsi Avatar answered Oct 14 '22 17:10

Szilard Muzsi