Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported
The error is fairly clear - you can't bind directly to the query results, but need to populate some local collection instead.
The simplest way to do this is to convert it to a List<T>
, via ToList()
:
ddlCon.DataSource = (from em in dw.Employees
select new { em.Title, em.EmployeeID }).ToList();
Or if you want to avoid writing a LINQ expression you could just do this:
var dbContext = new EF.CustomerEntities();
gvCustomers.DataSource = dbContext.CustomersTable.ToList();