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.
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.
This causes the server to return errors like
No property or field 'tostring' exists in type 'String' – when called with $filter=substringof('asd',tostring).
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?
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$filter=substring(‘mydesc’, $it) or
$filter=length($it) ge 5
etc. You can also expose collections of other primitives like IQueryable etc.