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

前端 未结 3 1126
有刺的猬
有刺的猬 2020-11-28 11:10

Am coding on visual studio 2012 and using Entity Model as my Data layer. However, my drop down control with the Linq statement tend to thro

3条回答
  •  悲&欢浪女
    2020-11-28 11:55

    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, via ToList():

     ddlCon.DataSource = (from em in dw.Employees
                                 select new { em.Title, em.EmployeeID }).ToList();
    

提交回复
热议问题