Blog Stats
  • Posts - 3
  • Articles - 1
  • Comments - 6
  • Trackbacks - 0

 

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

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

Feedback

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.

Gravatar thank you. it works...
11/2/2012 5:59 AM | mesut corut

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.

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(). 11/21/2012 12:16 PM | sbower

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.

Gravatar Thank's guys very help me out...! 12/13/2012 8:18 AM | Eri

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.

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 ;) 3/3/2013 10:45 PM | Omid

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.

Gravatar THanks it helped but still if you can explain a little bit more why we have to convert it to list. 3/31/2013 5:12 PM | Faisal Jawaid

# re: Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported.

Gravatar Thanks,It helped .. 4/30/2013 2:02 PM | Nandish

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © Chandradev