Geeks With Blogs
Chandradev's Blog
Hi

I was doing some test with code first approach in EF. Then while populating the Gridview i was getting error like this


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

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()
Posted on Monday, April 9, 2012 6:21 AM Entity Framework | Back to top


Comments on this post: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
thank you. it works...
Left by mesut corut on Nov 02, 2012 5:59 AM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Thank you for this post I have been searching all night for the answer and it was a simple solution by adding the .ToList().
Left by sbower on Nov 21, 2012 12:16 PM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Thank's guys very help me out...!
Left by Eri on Dec 13, 2012 8:18 AM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Thank You For This Topic , But i Adding .ToList() And This Eror : "The underlying provider failed on Open."
Sorry I Cant Type Good English Language.
So Thank You ;)
Left by Omid on Mar 03, 2013 10:45 PM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
THanks it helped but still if you can explain a little bit more why we have to convert it to list.
Left by Faisal Jawaid on Mar 31, 2013 5:12 PM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Thanks,It helped ..
Left by Nandish on Apr 30, 2013 2:02 PM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Thank u for this
Perfect !!!
Left by Robert Österberg on Dec 20, 2013 1:07 AM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
thanks man
Left by ابراهيم on Feb 26, 2014 3:21 AM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Thank u very very much dear
Left by Mawla Ali Kalandar on Jul 01, 2014 4:08 AM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Great ...it works
Left by sonu on Jul 02, 2014 7:20 PM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
great its work
Left by Akber Ali on Jul 24, 2014 11:30 PM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Thank you so much. It works.
Left by Gerson on Aug 02, 2014 10:14 PM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Tks so much.
Left by Cuti37 on Nov 17, 2014 7:00 AM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Thank you so much it helps me alot..
Left by Muhammad Hassan on Mar 02, 2015 12:46 AM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Thanks dear Its properly working
Left by Pawan on Mar 18, 2015 5:39 PM

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
Amazing...this one worked after hours of googling... Thanks a lot.
Left by HR on Mar 24, 2015 3:14 AM

# re: Data binding dirzet, DbQuery, DbSqlQuery) is not supported.
Requesting Gravatar...
thanks dear,
so you can use this

using (var context=new DatabaseEntities())
{
var q = from p in context.Employees select new { p.Id, p.Emp_Name, p.Emp_Address };
GridView1.DataSource = q.ToList();
GridView1.DataBind();
}
Left by masoud on Mar 29, 2015 4:29 PM

Your comment:
 (will show your gravatar)


Copyright © Chandradev | Powered by: GeeksWithBlogs.net