Although this seems very basic but i am struggling a lot in getting the concept,how actually left join works?and what is the purpose of into keyword meaning when there is no chance of grouping then why it is used to achieve left join??how and what we are grouping here??
public class LinqJoinController : Controller
{
//
// GET: /LinqJoin/
public List<Department> getAllDepartment()
{
return new List<Department>(){
new Department{Id=1,Name="IT"},
new Department{Id=2,Name="HR"},
};
}
public List<Employee> getAllEmployee()
{
return new List<Employee>(){
new Employee{Id=1,Name="Sachin",DepartmentId=1},
new Employee{Id=2,Name="Ram",DepartmentId=1},
new Employee{Id=3,Name="Shyam",DepartmentId=2},
new Employee{Id=4,Name="Radhe"},
};
}
public ActionResult Index()
{
var result = from emp in getAllEmployee()
join dep in getAllDepartment()
on emp.DepartmentId equals dep.Id
into eGroup
from dep in eGroup.DefaultIfEmpty()
select new EmployeeVM
{
DepartmentName = dep==null?"No Dept":dep.Name,
EmployeeName = emp.Name
};
return View(result);
}
}
}