EntityFramework NeedDataSource Best Practice

2 posts, 0 answers
  1. Richard
    Richard avatar
    35 posts
    Member since:
    Jun 2009

    Posted 29 Aug 2017 Link to this post

    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()?

  2. Eyup
    Admin
    Eyup avatar
    3825 posts

    Posted 04 Sep 2017 Link to this post

    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.
Back to Top