OData的$过滤substringof应用到字符串列表 [英] OData $filter substringof applied to a list of strings
问题描述
我有暴露了的IQueryable(串)的ASP.NET Web API控制器
- 这是描述的列表。这些字段可以在成千上万的顺序,所以我用 $顶部
和 $跳过
来只得到它的大块 - 工作正常。
I have an ASP.NET Web API Controller that exposes an IQueryable(Of String)
- which is a list of descriptions. These fields can be in the order of tens of thousands, thus I use $top
and $skip
to only get a chunk of it - that works fine.
现在我想筛选这些结果,通过的OData substringof('mydesc',属性)
过滤器。正如你所看到的,它需要我在属性命名要筛选通过。但是,因为我返回一个字符串列表,我实际上没有任何属性筛选依据。
Now I am trying to filter these results, through the OData substringof('mydesc',Property)
filter. As you can see, it requires for me to pass in a Property name on which to filter. However, since I'm returning a list of strings, I don't actually have any properties to filter on.
这将导致服务器返回的错误一样无属性或字段'的toString'类型'字符串'
存在 - 当 $过滤器= substringof(ASD,的toString)名为
。
This causes the server to return errors like
No property or field 'tostring' exists in type 'String'
- when called with $filter=substringof('asd',tostring)
.
如果我改变调用 $ =过滤substringof('ASD','')
,不会引发任何错误,但没有任何结果。
If I change the call to $filter=substringof('asd','')
, no errors are thrown, but no results either.
我的问题是,我能以某种方式格式化 $过滤器
运营商找到我的字符串列表内子,没有寻找一个属性/字段,还是我去要声明一个类有一个属性,只需启用过滤功能?
My question is, can I somehow format the $filter
operator to find substrings within my list of strings, without looking for a property/field, or am I going to have to declare a class with a single property, just to enable filtering?
推荐答案
自从我最后一次回答了这个事情已经改变了。 V3 OData的有查询使用'$它的原语集的支持。 Asp.net的Web API支持此语法为好。例如,在你的控制器就可以返回的IQueryable<串GT;
并发送类似
Things have changed since the last time I answered this. OData V3 has support for querying collection of primitives using '$it'. Asp.net Web API supports this syntax as well. For example, in your controller you can return IQueryable<string>
and send a request like
$ =过滤字符串('mydesc',$),或者
$filter=substring('mydesc', $it) or
$ =过滤器长度($吧)GE 5
$filter=length($it) ge 5
等。您也可以公开的其他元素的集合喜欢的IQueryable等。
etc. You can also expose collections of other primitives like IQueryable etc.
这篇关于OData的$过滤substringof应用到字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!