Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning to view as ToList() not working

I have this code:

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

and my EmployeeEntities class looks like this:

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

Why I cannot see ToList() in my ActionResult Index() ???

like image 616
RG-3 Avatar asked Dec 03 '25 19:12

RG-3


2 Answers

Add the namespace where the .ToList() extension method is defined:

using System.Linq;

to the top of your file.

like image 148
Darin Dimitrov Avatar answered Dec 06 '25 08:12

Darin Dimitrov


These functions are "Extension Methods", defined in Linq. That's why you need to reference System.Linq regardless of whether you are using Entity Framework or not.

Add the namespace where the .ToList() extension method is defined:

using System.Linq;

to the top of your file.

like image 43
Believe2014 Avatar answered Dec 06 '25 08:12

Believe2014



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!