Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
- by Chandradev
HiI was doing some test with code first approach in EF. Then while populating the Gridview i was getting error like thisData
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().For solving this error we have to write the code like this private void FillGrid() { using (var Context = new EmpDatabaseContext()) { var query = Context.Emps.Select(m => m); //var query = from m in Context.Emps // select m; // Gridview1.DataSource = query; Gridview1.DataSource = query.ToList(); Gridview1.DataBind(); } } We canot bind Iqueryable directly. We have to change into ToList()