返回到视图时ToList()不起作用



我有这样的代码:

EmployeeEntities storeDB = new EmployeeEntities();
         public ActionResult Index()
            {
                var employee = storeDB.Employees.ToList() //ToList is not showing up!
                return View(employee);
            }

和我的EmployeeEntities类看起来像这样:

 public class EmployeeEntities : DbContext
{
    public DbSet<Employee> Employees { get; set; }
}

为什么我不能看到ToList()在我的ActionResult Index() ??

添加定义.ToList()扩展方法的命名空间:

using System.Linq;

这些函数是在Linq中定义的"扩展方法"。这就是为什么你需要参考系统。Linq不管你是否使用实体框架

添加定义.ToList()扩展方法的命名空间:

using System.Linq;

放到文件的顶部

最新更新