WebAPI 2.2不支持substringof函数

时间:2014-07-28 11:59:23

标签: asp.net-web-api odata

我支持OData的WebAPI 2.2服务。

我的控制器有一个返回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",

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

1 个答案:

答案 0 :(得分:47)

substringof() V3 功能,而contains() V4 功能。

尝试包含:

$filter=contains(Name,'Queen')
相关问题