Not able to use oData query options
Asked Answered
D

4

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?

Diminutive answered 28/8, 2012 at 14:45 Comment(1)
Now it is supported asp.net/web-api/overview/odata-support-in-aspnet-web-api/…Illuse
B
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.

Buckwheat answered 28/8, 2012 at 15:21 Comment(1)
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.Buckwheat
A
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

Alishiaalisia answered 2/9, 2012 at 7:24 Comment(0)
A
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 < [email protected] >
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.

Anacardiaceous answered 18/1, 2013 at 18:7 Comment(1)
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.)Anacardiaceous
A
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.

Agone answered 28/4, 2013 at 21:16 Comment(2)
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'Enshrine
thanks @choco but I gave up on oData long ago - was too much of a messAgone

© 2022 - 2024 — McMap. All rights reserved.