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

前端 未结 3 1104
有刺的猬
有刺的猬 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:52

    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();
    
    0 讨论(0)
  • 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<T>, via ToList():

     ddlCon.DataSource = (from em in dw.Employees
                                 select new { em.Title, em.EmployeeID }).ToList();
    
    0 讨论(0)
  • 2020-11-28 12:04

    though this question has already been answered still I want to show that you can even get the answer directly from the message box as well (i got the same error) ERROR DIALOGUE BOX IMAGE

    using (var retrive=new Models.Academy_MSDBEntities())
            {
                var query = retrive.Students.Where(s => s.Year == year).ToList();
                return query;
            }
    
    0 讨论(0)
提交回复
热议问题