Filtering using Entity Framework query in NeedDataSource

4 posts, 0 answers
  1. Malcolm
    Malcolm avatar
    5 posts
    Member since:
    Feb 2012

    Posted 24 May Link to this post

    How do I use the grid filter expresssion in an entity framework query in the NeedDataSource method?

    For example after selecting from the grid column filters the filter expression is:

    (iif(Comment == null, "", Comment).ToString().ToUpper().Contains("test".ToUpper())) AND (iif(OrderNo == null, "", OrderNo).ToString().ToUpper().StartsWith("830".ToUpper()))

    How do I use it in my EF query

    var orders = db.Orders.Where(o=>o.Status == 2);

    Thanks.

     

  2. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 27 May Link to this post

    Hello Malcolm,

    You should let the RadGrid handle the data-binding logic:
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/automatic-crud-operations/defaultcs.aspx

    Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:

    Declarative DataSource (DataSourceID property)
    Programmatic Data Binding (NeedDataSource event, + DetailTableDataBind for hierarchy). You should set the DataSource property ONLY within these event handler.

    In your case passing the raw database within the NeedDataSource event should be enough. RadGrid will apply the filter and sorting expressions accordingly and extract the necessary items automatically.

    Regards,
    Eyup
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Malcolm
    Malcolm avatar
    5 posts
    Member since:
    Feb 2012

    Posted 28 May in reply to Eyup Link to this post

    Eyup said:

    In your case passing the raw database within the NeedDataSource event should be enough. RadGrid will apply the filter and sorting expressions accordingly and extract the necessary items automatically.

     

    But, if the filtering and sorting is left to the RadGrid, doesn't that mean that every record will need to be retrieved from that database and into in memory so that RadGrid can page, filter and sort them.

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 01 Jun Link to this post

    Hello,

    You are right and this is exactly how the RadGrid operations work. There is no possibility to apply load on demand for the RadGrid data.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top