Ticket T626509
Visible to All Users

How to use CriteriaToWhereClauseHelper in a MVC application

created 7 years ago (modified 7 years ago)

[DevExpress Support Team: CLONED FROM K18434: How to convert the CriteriaOperator to the corresponding filter string in order to use it for building SQL queries or for filtering the DataView]
Hi,

I have a MVC Core API (target framework .Net Core 2.0), it provide data for my dxDataGrids.
How to add DevExpress.Data.Filtering.CriteriaToWhereClauseHelper into my project and using helpers method like as above guideline?
I cannot find DevExpress.Data.Filtering  library file (.dll) in anywhere.  I also connect to DevExpress Nuget server and searching keywork "DevExpress.Data" but it's no results.

Current code:

C#
using DevExtreme.AspNet.Mvc; using DevExtreme.AspNet.Data; [HttpGet] public virtual object Get(DataSourceLoadOptions loadOptions) { var list = _dbContext.Products.Where(x => x.ParentId == parentId); return DataSourceLoader.Load(list, loadOptions); }

Regards,

Comments (3)
DevExpress Support Team 7 years ago

    Hi Henry,

    DevExtreme components have their own implementation unrelated to our ASP.NET MVC Extensions. That is why DevExpress.Data.Filtering.CriteriaToWhereClauseHelper is not present in your project. The DataSourceLoader.Load method returns data according to the load options received from the client. If your dxDataGrid has a filter expression, you will get it as the loadOptions.Filter parameter of the Get controller action.

    Would you please clarify why and where you need to use DevExpress.Data.Filtering.CriteriaToWhereClauseHelper? It would be great if you also describe your final goal in greater detail. We will do our best to help you.

      Hi Nikolai,

      Thank you for responding,

      I have some business page and its reach up to hundreds thousand records.
      #1 I make a flexible query string to included security filter and something else
      #2 I call Dapper to execute query (Dapper.Query return IEnumerable<T>)
      #3 I call DataSourceLoader.Load(list, loadOptions);

      I would like to have WHERE clause from loadoptions.Filter to build-in it into queryString before execute it by Dapper to reduce data query/return from database.

      Current code:

      C#
      try { if (super == false) { queryCmd = Util.ApplyDataFilter(queryCmd); } // return data var list = Util.DapperExecuteQuery<object>(Util.GetConnectionString(), queryCmd, null); // on custom get onExecuteGet(ref list); return DataSourceLoader.Load(list, loadOptions); } catch (Exception e) { throw new CustomException($"Execute [{eqdQuery.Name}] was failed. {e.Message}", e); } public static IEnumerable<T> DapperExecuteQuery<T>(string conn, string sqlString, object param) { using (var dbConn = new SqlConnection(conn)) { return dbConn.Query<T>(sqlString, param); } }

      Regards,

      DevExpress Support Team 7 years ago

        Hello Henry,
        As Nikolai mentioned, you can add extra filtering criteria directly to the loadOptions.Filter  property. Is it a possible solution for you? I have created a small test sample that illustrates this approach? I hope to hear from you soon.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.