Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebAPI 2.2 does not support substringof function

I've a WebAPI 2.2 service with OData support.

My controller has an action which returns an IQuerable<Entity>, but I'm unable to use $filter=substringof function even if I allow all functions.

[Authorize]
public class MyController : ODataController
{
    [EnableQuery(AllowedFunctions=AllowedFunctions.All)]
    public IQueryable<Entity> GetEntities()
    {
      return GetMyQueryable();
    }
}

When I hit a URL like http://localhost:49844/Entities/?$filter=substringof('Queen',Name)

I get an error saying substringof is not allowed.

{
"error": {
    "code": "",
    "message": "The query specified in the URI is not valid. An unknown function with name 'substringof' was found. This may also be a function import or a key lookup on a navigation property, which is not allowed.",
    "innererror": {
        "message": "An unknown function with name 'substringof' was found. This may also be a function import or a key lookup on a navigation property, which is not allowed.",
        "type": "Microsoft.OData.Core.ODataException",

Any idea why I might be seeing this error?

like image 852
BuddhiP Avatar asked Jul 28 '14 11:07

BuddhiP


Video Answer


1 Answers

substringof() is a V3 function while contains() is a V4 function.

Try contains:

$filter=contains(Name,'Queen')
like image 167
Tan Jinfu Avatar answered Dec 26 '22 15:12

Tan Jinfu