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

EntityFramework NeedDataSource Best Practice

1 Answer 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 29 Aug 2017, 01:52 PM

I am using Entity Framework with a MySQL database to store a table of hundreds of thousands of packages. When I try to bind directly to the query:

protected void OnPackagesNeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    PackageGrid.DataSource = PageServerDataContext.Packages;
}

I get the error, "Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery, DbRawSqlQuery) is not supported."

Using .ToList() would mean that I need to load all the packages in the database, which is not practical.

I can use an EntityDataSource, but I would rather set the data programmatically. 

How do I use NeedDataSource with EntityFramework without using .ToList()?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 04 Sep 2017, 05:21 AM
Hello Richard,

When binding the RadGrid control, you should pass a collection which holds the records physically, not only some virtual query or promise. The valid source can be a DataSet or DataTable for example:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-binding/understanding-data-binding/server-side-binding/various-data-sources/binding-to-datatable-or-dataset

Or any kind of list of objects implementing IEnumerable interface:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-binding/understanding-data-binding/server-side-binding/various-data-sources/binding-to-an-arraylist

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or