7

I have an ASP.NET Web API project. I'm trying to pass some query options to my API controller like so:

http://localhost:61736/api/Enquiries?
callback=callback&$top=30&$skip=30&orderby=EnquiryId
&$inlinecount=allpages&_=1346164698393

But I get the following:

The query parameter '$inlinecount' is not supported.

I also get the same when I try to use $callback, $format

Any idea what I'm doing wrong? According to: http://msdn.microsoft.com/en-us/library/ff478141.aspx I should be able to use them?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
CallumVass
  • 11,288
  • 26
  • 84
  • 154
  • 1
    Now it is supported http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options – Brij May 02 '13 at 16:19

4 Answers4

7

The ASP.NET Web API provides only limited support for OData as documented in this blog post. I didn't see the query parameters you mention in that list.

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
  • I guess you could you create an ApiController that would be a proxy to a regular OData based service. The OData service would actually perform the query and your controller would just return responses. – Sixto Saez Aug 28 '12 at 18:17
2

In current version, web api only supports $filter, $orderby, $top and $skip. You can override QueryableAttribute to add more support on OData protocol. A checkin after public nuget release has made ValidateQuery method virtual so that you can override it to bypass the validation. Please try our nightly build at http://www.myget.org/F/aspnetwebstacknightly/.

You can also use ODataQueryOptions. The following code is equivalent to [Queryable] attribute, except that it won't throw exception when it sees unsupported options.

public IEnumerable<Product> Get(ODataQueryOptions options) 
{
    return options.ApplyTo(_db.Products as IQueryable) as IEnumerable<Product>; 
}

You can get $inlinecount by ODataQueryOptions.RawValues.InlineCount. For detail of OData query support, please see: http://blogs.msdn.com/b/alexj/archive/2012/08/21/web-api-queryable-current-support-and-tentative-roadmap.aspx

Hongye Sun
  • 3,868
  • 1
  • 25
  • 18
2

Support for $inlinecount was checked into the project on 12/6/2012, presumably the next release will contain this support. you can download the latest source or pick up a nightly build:

http://aspnetwebstack.codeplex.com/SourceControl/changeset/ed65e90e83c8

Revision: ed65e90e83c8f9391b4f4806d305c83f55d28ff6
Author: youssefm < youssefm@microsoft.com >
Date: 12/6/2012 1:51:44 PM
Message:
[OData] Add support for the $inlinecount query option

I believe nightly packages are pushed to http://www.myget.org/F/aspnetwebstacknightly/ but I have not verified myself.

Shaun Wilson
  • 8,727
  • 3
  • 50
  • 48
  • The current nightly build doesn't complain about $inlinecount, but it also doesn't provide a properly formatted response which includes count (e.g. no change in behavior.) – Shaun Wilson Jan 18 '13 at 18:32
1

If you're using KendoUI by any chance this post explains how to disable some of the options such as $callback by switching to JSON instead of JSONP.

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • 1
    Kendo now supports ODATA V4 there is no longer any need for tweaks to make it work. You can change the data set type from type: 'odata' to type: 'odata-v4' – Choco Oct 13 '15 at 05:27
  • 1
    thanks @choco but I gave up on oData long ago - was too much of a mess – Simon_Weaver Oct 13 '15 at 07:32