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
    Eyup avatar
    4085 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:

    Or any kind of list of objects implementing IEnumerable interface:

    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