I have an asp.net 4.5 Web Api oData v4 service that is working really well but I have encountered a problem today with nested $filters in $expand.
我有一个asp.net 4.5 Web Api oData v4服务,它运行得非常好,但是我今天遇到了$expand中嵌套的$filter的问题。
It says here
在这里说
that OData V4 supports nested filters in $expand. The request below return People and all their trips with Name "Trip in US".
OData V4支持$expand中的嵌套过滤器。下面的请求返回了人们和他们的所有旅行,名字为“我们在美国旅行”。
GET serviceRoot/People?$expand=Trips($filter=Name eq 'Trip in US')
得到serviceRoot /人?$expand=Trips($filter=Name eq 'Trip in US')
and it shows a nice example of data that does just that.
它展示了数据的一个很好的例子。
There is also a coded example in the Web API for oData v4 Docs here
这里还有一个oData v4文档的Web API编码示例
I have an HTTP call like this:
我有一个像这样的HTTP调用:
serviceRoot/Languages?$expand=translations
which returns a list of Languages with their expanded translations and I can filter that top-level list down with this:
它返回一个带有扩展翻译的语言列表,我可以用以下方法过滤顶层列表:
serviceRoot/Languages?$expand=translations&$filter=isoLanguageShortName eq 'en'
However, I can't filter the expanded translations with this:
但是,我不能用这个来过滤扩展的翻译:
serviceRoot/Languages?$expand=translations($filter=languageName eq 'English')
That call seems to be the same as the one in the quote above and the effect should be same on my data as theirs.
这个调用看起来和上面引用的一样,对我的数据的影响应该和他们的一样。
Does anyone know where am I going wrong? Do I need to set something in my ASP.NET code for this to work (like we need to add MaxExpansionDepth to EnableQueryAttribute for querying deeper than two levels)?
有人知道我哪里出错了吗?我需要在ASP中设置一些东西吗?这要使用的NET代码(比如我们需要向EnableQueryAttribute添加maxexpandepth,以便查询深度超过两个级别)?
1 个解决方案
#1
1
It is a versioning problem. The support for has been added with version 5.5. I tested the sample with v5.5.1 and it is actually working.
这是一个版本控制问题。版本5.5增加了对它的支持。我用v5.5.1测试了这个样品,它确实有效。
As @lukkea confirmed he was using 5.4.0.
@lukkea确认他使用的是5.4.0。
(Version 6.1.0 indicated in the title corresponds to odata core libraries which is a dependency of odata web api library Microsoft.AspNet.OData)
(标题中显示的版本6.1.0对应于odata core库,它是odata web api库Microsoft.AspNet.OData的一个依赖项)
#1
1
It is a versioning problem. The support for has been added with version 5.5. I tested the sample with v5.5.1 and it is actually working.
这是一个版本控制问题。版本5.5增加了对它的支持。我用v5.5.1测试了这个样品,它确实有效。
As @lukkea confirmed he was using 5.4.0.
@lukkea确认他使用的是5.4.0。
(Version 6.1.0 indicated in the title corresponds to odata core libraries which is a dependency of odata web api library Microsoft.AspNet.OData)
(标题中显示的版本6.1.0对应于odata core库,它是odata web api库Microsoft.AspNet.OData的一个依赖项)