How to ignore case using breeze FilterQueryOp

北城余情 提交于 2019-12-05 08:49:10

Ok, there are two parts to this. Breeze supports a LocalQueryComparisonOptions object that is used for all localQueries.

    var lqco = new breeze.LocalQueryComparisonOptions({
        name: "custom comparison options",
        isCaseSensitive: false,
        usesSql92CompliantStringComparison: true
    });
    // either apply it globally
    lqco.setAsDefault();
    // or to a specific MetadataStore
    var ms = new breeze.MetadataStore({ localQueryComparisonOptions: lqco });
    var em = new breeze.EntityManager( { metadataStore: ms });

You should set this once at the beginning of your application. In this example, all localQueries performed after this point will be case insensitive.

The problem is that unless your database is ALSO set to "match" these settings ( performing this differs by database vendor), then remote queries against the server will return different results then the same query applied locally.

Basically, Breeze cannot set the "server" side implementation, so the recommendation is usually to create a localQueryComparisons object that matches your server side database settings.

Hope this makes sense.

In my opinion there is a simpler approach to this.

By default OData is case sensitive, but nonetheless provides functions to transform a string to lower or upper case. So to fire a case-insensitive query to the server simply modify your code as follows:

var term = "john"; 
query = query.where("tolower(Name)", breeze.FilterQueryOp.Contains, term.toLowerCase());

Thus OData is told to transform the subject to lower case before comparing it to your search string, which has been converted to lower case before sending it to the server.

If anyone run into this problem on an Oracle DB, I added the code above from Jay Traband then modified a logon trigger to alter session variables for DB users. Set the following values:

ALTER SESSION SET nls_comp = linguistic; ALTER SESSION SET nls_sort = binary_ci

Hope this helps someone out. I love Breeze!!!

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