我有一个具有OData支持的WebAPI 2.2服务。

我的 Controller 有一个返回IQuerable<Entity>的操作,但是即使允许所有功能,我也无法使用$filter=substringof函数。

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

当我点击http://localhost:49844/Entities/?$filter=substringof('Queen',Name)这样的网址时

我收到一条错误消息,说不允许substringof。
{
"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",

知道为什么我会看到此错误吗?

最佳答案

substringof() V3 函数,而contains() V4 函数。

尝试包含:

$filter=contains(Name,'Queen')

关于asp.net-web-api - WebAPI 2.2不支持substringof函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24994774/

10-11 10:33