简体   繁体   English

无法使用oData查询选项

[英]Not able to use oData query options

I have an ASP.NET Web API project. 我有一个ASP.NET Web API项目。 I'm trying to pass some query options to my API controller like so: 我试图将一些查询选项传递给我的API控制器,如下所示:

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 当我尝试使用$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? 根据: http//msdn.microsoft.com/en-us/library/ff478141.aspx我应该可以使用它们吗?

The ASP.NET Web API provides only limited support for OData as documented in this blog post. ASP.NET Web API仅为OData提供有限的支持,如本博文中所述。 I didn't see the query parameters you mention in that list. 我没有看到你在该列表中提到的查询参数。

In current version, web api only supports $filter, $orderby, $top and $skip. 在当前版本中,web api仅支持$ filter,$ orderby,$ top和$ skip。 You can override QueryableAttribute to add more support on OData protocol. 您可以覆盖QueryableAttribute以在OData协议上添加更多支持。 A checkin after public nuget release has made ValidateQuery method virtual so that you can override it to bypass the validation. 公共nuget发布后的checkin使ValidateQuery方法变为虚拟,以便您可以覆盖它以绕过验证。 Please try our nightly build at http://www.myget.org/F/aspnetwebstacknightly/ . 请在http://www.myget.org/F/aspnetwebstacknightly/上尝试我们的夜间构建。

You can also use ODataQueryOptions. 您还可以使用ODataQueryOptions。 The following code is equivalent to [Queryable] attribute, except that it won't throw exception when it sees unsupported options. 以下代码等同于[Queryable]属性,但它在看到不支持的选项时不会抛出异常。

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

You can get $inlinecount by ODataQueryOptions.RawValues.InlineCount. 你可以通过ODataQueryOptions.RawValues.InlineCount获得$ 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 有关OData查询支持的详细信息,请参阅: http//blogs.msdn.com/b/alexj/archive/2012/08/21/web-api-queryable-current-support-and-tentative-roadmap.aspx

Support for $inlinecount was checked into the project on 12/6/2012, presumably the next release will contain this support. 2012年12月6日在项目中检查了对$ inlinecount的支持,可能下一个版本将包含此支持。 you can download the latest source or pick up a nightly build: 您可以下载最新的资源或每晚构建:

http://aspnetwebstack.codeplex.com/SourceControl/changeset/ed65e90e83c8 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. 我相信每晚的软件包都会被推送到http://www.myget.org/F/aspnetwebstacknightly/,但我还没有验证自己。

如果您有任何机会使用KendoUI, 这篇文章将解释如何通过切换到JSON而不是JSONP来禁用某些选项,例如$ callback。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM