Entity framework 4 按集合列表将数据绑定到网格时出错

Entity framework 4 按集合列表将数据绑定到网格时出错,entity-framework-4,entity,Entity Framework 4,Entity,我试图将列表集合绑定到数据网格,但它给出了一个错误 类型“System.Data.Objects.ObjectContext”是在未引用的程序集中定义的。必须添加对程序集“System.Data.Entity,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”的引用 数据层代码: public class Employees { public List<Employee> LoadEmployees

我试图将列表集合绑定到数据网格,但它给出了一个错误

类型“System.Data.Objects.ObjectContext”是在未引用的程序集中定义的。必须添加对程序集“System.Data.Entity,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”的引用

数据层代码:

  public class Employees
 {
 public List<Employee> LoadEmployees()
     {
         try
         {
             EMployeeDB1Entities EE = new EMployeeDB1Entities();
             var Employees = EE.Employees.Where(p => p.Name.StartsWith("T"));
             return Employees.ToList();

            // var myCollection = new ObservableCollection<Employee>(this.LoadEmployees());

         }
         catch
         {
             return null;
         }
解决办法是什么?
提前感谢…

错误清楚地表明您在项目中缺少System.Data.Entity类的引用,您需要通过相同的简单过程添加它。右键单击添加引用,然后单击.Net选项卡并从列表中选择System.Data.Entity


您可以开始了。

您在UI项目中引用了
System.Data.Entity
了吗?
   private void button1_Click(object sender, EventArgs e)
    {

        Employees E1 = new Employees();

        // error gives in below line.
        dataGridView1.DataSource = E1.LoadEmployees();


    }