Saurabh

Saurabh

  • NA
  • 42
  • 5.7k

LINQ - No output

Apr 23 2019 7:58 AM
I am unble to find records for Employees table in the following code. I have used Entity data model.
Here for Console.WriteLine("Department Name = " + dept.Name ); output is coming but for dept.Employees.Count() is 0.
 
using (EmpDBContext dbcontext = new EmpDBContext())
 {
            var departments = from dept in dbcontext.Departments
                                          where dept.Name == "IT"
                                          select dept;

            foreach (var dept in departments)
            {
               Console.WriteLine("Department Name = " + dept.Name );
               Console.WriteLine("count is " + dept.Employees.Count());
                       
               //var employees = from e in dept.Employees
               //                            where e.ID == dept.ID && e.Gender == "Male"
               //                            select e;

             }

              Console.ReadKey();
   }

Answers (6)