using System.Collections.Generic;
public static void Main()
public static void LeftOuterJoinExample()
Person magnus = new Person { Id= 1, FirstName = "Magnus", LastName = "Hedlund" };
Person terry = new Person { Id = 2, FirstName = "Terry", LastName = "Adams" };
Person charlotte = new Person { Id = 3, FirstName = "Charlotte", LastName = "Weiss" };
Person arlene = new Person { Id = 4, FirstName = "Arlene", LastName = "Huff" };
Pet barley = new Pet { Id = 1, Name = "Barley", Owner = terry };
Pet boots = new Pet { Id = 2, Name = "Boots", Owner = terry };
Pet whiskers = new Pet { Id = 3, Name = "Whiskers", Owner = charlotte };
Pet bluemoon = new Pet { Id = 4, Name = "Blue Moon", Owner = terry };
Pet daisy = new Pet { Id = 5, Name = "Daisy", Owner = magnus };
List<Person> people = new List<Person> { magnus, terry, charlotte, arlene };
List<Pet> pets = new List<Pet> { barley, boots, whiskers, bluemoon, daisy };
var query = from person in people
join pet in pets on person.Id equals pet.OwnerId into gj
from subpet in gj.DefaultIfEmpty()
group person by person.Id into temp1
Console.WriteLine(string.Format("query count: {0}", query.Count()));
var query1 = from person in people
join pet in pets on person.Id equals pet.OwnerId into gj
from subpet in gj.DefaultIfEmpty()
Console.WriteLine(string.Format("query count no grouping: {0}", query1.Count()));
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Id { get; set; }
public int? OwnerId { get; set; }
public string Name { get; set; }
private Person _ownerPerson;
get { return _ownerPerson; }