2016-04-21 39 views
0

我有一個複雜的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

兩者的屬性和在$filter的文字串需要被轉換爲小寫。由於文字字符串始於客戶端,因此您可以通過在發送OData請求之前將其轉換爲lowercase之前進行優化。

$filter=startswith(tolower(FirstName),'fahad') or startswith(tolower(LastName),'fahad') 

請注意,文字字符串必須在過濾器表達式中用單引號括起來。

相關問題