This is a migrated thread and some comments may be shown as answers.

Filtering using Entity Framework query in NeedDataSource

3 Answers 321 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Telstra Software Licensing
Top achievements
Rank 1
Telstra Software Licensing asked on 24 May 2016, 09:29 AM

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.

 

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 27 May 2016, 06:29 AM
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.
0
Telstra Software Licensing
Top achievements
Rank 1
answered on 28 May 2016, 10:06 AM

[quote]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.

[/quote]

 

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.

0
Maria Ilieva
Telerik team
answered on 01 Jun 2016, 02:47 PM
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.
Tags
Grid
Asked by
Telstra Software Licensing
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Telstra Software Licensing
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or