我有一个复杂的odata查询,我使用OdataAngularResrouce库通过Angular。众所周知,odata查询区分大小写,显然我不知道数据是如何存储在数据库中的。这是我用来构建查询的谓词。
var predicFirstName = new $odata.Predicate(new $odata.Func("startswith", "FirstName", new $odata.Func("tolower", $scope.searchObject.searchString)), true);
var predicLastName = new $odata.Predicate(new $odata.Func("startswith", "LastName", new $odata.Func("tolower", $scope.searchObject.searchString)));
**OData URI:**
https://localhost/app/TylerIdentityUserAdministrationService/Users/$count/?$filter=((startswith(FirstName,tolower(Fahad)))%20or%20startswith(LastName,tolower(Fahad)))
正如您所看到的,我想放置一个函数来仅检查带有startswith的给定字符串。我已经看到几个帖子,解决方案是放置tolower()。但是,当我按照上面提到的方式使用它时,它不返回任何数据。有人可以帮忙吗?
由于 -Fahad
答案 0 :(得分:0)
Both the properties and the literal strings in the $filter
need to be converted to lowercase. And since the literal strings originate on the client, you can optimize by converting them to lowercase before you send the OData request.
$filter=startswith(tolower(FirstName),'fahad') or startswith(tolower(LastName),'fahad')
Note that the literal strings must be surrounded with single quotes in the filter expression.