using System.Collections.Generic;
public static void Main()
var employees = new EmployeeRepo();
var states = new StateRepo();
SimpleJoin(employees.Get(), states.Get());
Console.WriteLine("======================");
OuterJoin(employees.Get(), states.Get());
public static void SimpleJoin(List<Employee> employees, List<State> states)
join s in states on e.StateId equals s.StateId
foreach (var employee in employeeByState)
Console.WriteLine(employee.LastName + ", " + employee.StateName);
public static void OuterJoin(List<Employee> employees, List<State> states)
join s in states on e.StateId equals s.StateId into employeeGroup
from item in employeeGroup.DefaultIfEmpty(new State{StateId = 0, StateName = "NA"})select new
e.LastName, item.StateName
foreach (var employee in employeeByState)
Console.WriteLine(employee.LastName + ", " + employee.StateName);
{StateId = 1, StateName = "PA"}, new State()
{StateId = 2, StateName = "NJ"}};
public class EmployeeRepo
public List<Employee> Get()
return new List<Employee>()
{FirstName = "John", LastName = "Smith", StateId = 1}, new Employee()
{FirstName = "Jane", LastName = "Doe", StateId = 2}, new Employee()
{FirstName = "Jack", LastName = "Jones", StateId = 1}, new Employee(){
FirstName = "Pawan", LastName = "Shakya", StateId = 3