Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported - Entity Framework

In Visual Studio 2015 I was using Entity Framework and wrote a code to bind data with GridView. I wrote the normal Linq and browse my web page. And surprised to see below line of error:

Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList().

Below is the code which was throwing above error.

using (var ctx = new PracticeEntities())
            {
                var data = from d in ctx.Orders select d;
                gvData.DataSource = data;
                gvData.DataBind();


            }

I changed above code to below and it works for me.


using (var ctx = new PracticeEntities())
            {
                var data = (from d in ctx.Orders select d).ToList();
                gvData.DataSource = data;
                gvData.DataBind();

            }

Comments

Popular

C# 6.0 New Features

SharePoint Interview Questions and Answers

Calling ASP.Net WebMethod using jQuery AJAX

What is Cloud Computing - A guide for beginners