public static void UseLeftInnerJoin() { var employeeRepository = new EmployeeRepository(); var departmentRepository = new DepartmentRepository(); var query = from d in departmentRepository.GetAll() join e in employeeRepository.GetAll() on d.ID equals e.ID into ed select new { Department = d.Name, Employees = ed }; foreach (var group in query) { Console.WriteLine(group.Department); foreach (var employee in group.Employees) { Console.WriteLine("\t" + employee.Name); } } }
//private static void UseGroup() //{ // var repository = new EmployeeRepository(); // var queryByDepartment = from e in repository.GetAll() // group e by e.DepartmentID // into eGroup //} public static void UseInnerJoin() { var employeeRepository = new EmployeeRepository(); var departmentRepository = new DepartmentRepository(); var query = from e in employeeRepository.GetAll() join d in departmentRepository.GetAll() on e.DepartmentID equals d.ID select new { Employee = e.Name, Department = d.Name }; foreach (var e in query) { Console.WriteLine("{0} {1}", e.Employee, e.Department); } }