OData query $filter conditions and case-sensitivity

妖精的绣舞 提交于 2019-11-27 04:27:39

问题


Does OData specify whether filter conditions on string fields are to be evaluated case-sensitively or case-insensitively?

Example: (from the docs)

/Suppliers?$filter=Address/City eq 'Redmond' 

Is this expected to be case-sensitive or not?

If I want to offer both options, how can this be expressed? There is a tolower() function that can be used like:

/Suppliers?$filter=tolower(Address/City) eq 'redmond'

or

/Suppliers?$filter=tolower(Address/City) eq tolower('Redmond')

Isn't there a more concise way to express case-insensitive matching?


回答1:


The "eq" operator is supposed to be case sensitive. Usage of tolower (or toupper) is the currently recommended way of doing this.




回答2:


It is now possible to do case insensitive compare by setting EnableCaseInsensitive = true on the ODataUriResolver. I used this with Microsoft.AspNetCore.OData 7.1.0.

     var oDataUriParser = new ODataUriParser(model, uri)
     {
        Resolver = new ODataUriResolver { EnableCaseInsensitive = true}
     };

Source: https://github.com/OData/WebApi/issues/812




回答3:


I would expect this is depended on your database collation setting, as the odata service is just performing a query. If Vitek's answer is correct, then odata is doing some post query filtering on the result set, and that should be strange, right?




回答4:


It doesn't depend on database. Even if you perform query against database in case in-sensitive way then OData will do his own additional filtering and filter your data out.



来源:https://stackoverflow.com/questions/13495905/odata-query-filter-conditions-and-case-sensitivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!