Asp.net web api odata4$筛选器返回错误结果
我正在使用DataTables odata插件来启动我的html表格。搜索时,我正在发送如下所示的筛选器属性:Asp.net web api odata4$筛选器返回错误结果,asp.net-web-api,odata,Asp.net Web Api,Odata,我正在使用DataTables odata插件来启动我的html表格。搜索时,我正在发送如下所示的筛选器属性: $filter= indexof(tolower(ClientAlias/Name), 'wee') gt -1 or indexof(tolower(Product/Name), 'wee') gt -1 or indexof (tolower(User/UserName), 'wee') gt -1 or indexof(tolower(Manager/FullName),
$filter=
indexof(tolower(ClientAlias/Name), 'wee') gt -1 or indexof(tolower(Product/Name), 'wee') gt -1 or indexof
(tolower(User/UserName), 'wee') gt -1 or indexof(tolower(Manager/FullName), 'wee') gt -1 and Status ne
webapi.Models.ContractStatus'Suspended' and Manager_Id eq '120'
然而,在结果中,我得到了与indexof函数的第一个过滤器完全匹配的所有内容。例如:
{
ClientAlias:Object{Name="weentertain"}
Manager:
Object { Id="55"}
}
其中Manager.Id甚至与我使用筛选器请求的Manager.Id不接近。
我的问题是,前面的筛选器是否覆盖了最后一个筛选器,或者我以错误的方式请求了它?首先,请注意,您给出的示例是对名为
Manager\u Id
的属性进行筛选,但在示例结果中未显示此类属性。您的意思是在管理器/Id
上进行筛选吗
您看到的结果是由于。和
运算符的优先级高于或
。可以通过使用括号将子字符串匹配一起覆盖优先级
最后,您可以使用函数代替indexof
/eq
组合来简化子字符串匹配
以下是重写的过滤器(为便于阅读,插入了换行符):
$filter=
(contains(tolower(ClientAlias/Name), 'wee') or
contains(tolower(Product/Name), 'wee') or
contains(tolower(User/UserName), 'wee') or
contains(tolower(Manager/FullName), 'wee')) and
Status ne webapi.Models.ContractStatus'Suspended' and
Manager/Id eq '120'