LINQ to SQL Left Outer Join

In this example we will write LINQ Left outer join on tblEmployees and tblDepartments table.

Input tables

Department table
departments


Employees table
employees


LINQ Query:

MyDBDataContext sqlObj = new MyDBDataContext(); var employees = from emps in sqlObj.tblEmployees join de in sqlObj.tblDepartments on emps.DepartmentID equals de.DepartmentID into dep from dept in dep.DefaultIfEmpty() select new { emps.EmployeeID, emps.EmployeeName, emps.Salary, dept.DepartmentName }; gvemployees.DataSource = employees; gvemployees.DataBind();

Output

left-outer-join