c# - 返回查看 ToList() 不工作

标签 c# asp.net-mvc asp.net-mvc-3

我有这个代码:

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; }
}

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

最佳答案

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

using System.Linq;

到文件的顶部。

关于c# - 返回查看 ToList() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7810556/

相关文章:

c# - 升级到 RC 后,具有多对多关系的实体创建失败

c# - 使用局部 View 时 MVC 模型 Null on post

asp.net - MVC3 : How to specify that a partial view be loaded when it is located in a different, 未搜索,文件夹?

asp.net-mvc-3 - 尝试在 View 中显示枚举中的 "Name"属性

c# - ASP.MVC 参数未传递给 http post 的 Action 方法

asp.net-mvc-3 - 对于 asp.net mvc3 Controller 来说,多少行代码太多了?

c# - 为什么这会导致预编译错误,即该词典类在当前上下文中不存在?

c# - 如何将 MainWindow.xaml 拆分为单独的文件? - 外包<Style>?

c# - "Is"C# 运算符就像java 中的instanceof 吗?

c# - 将范围为 "request"的对象注入(inject)原型(prototype)对象