Hi,
I am getting the following error when binding Entity Framework data to DataGridView.
An unhandled exception of type 'System.NotSupportedException' occurred in EntityFramework.dll
Additional information: 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().
Code:
private void Form1_Load(object sender, EventArgs e)
{
NorthwindEntities entities = new NorthwindEntities();
var customers = from p in entities.Customers
select new
{
CustomerId = p.CustomerID,
ContactName = p.ContactName,
Country = p.Country
};
dataGridView1.DataSource = customers;
}