Using extension syntax. I am trying to create a connection on the left using LINQ in the two lists that I have. Microsoft's help is below, but I modified it to show that the pet list does not have items. What I get is a list of 0 items. I suppose this is because an inner join is taking place. What I want to finish is a list of 3 elements (3 people objects) with zero data filled for missing elements. those. left connection. Is it possible?
Person magnus = new Person { Name = "Hedlund, Magnus" }; Person terry = new Person { Name = "Adams, Terry" }; Person charlotte = new Person { Name = "Weiss, Charlotte" }; //Pet barley = new Pet { Name = "Barley", Owner = terry }; //Pet boots = new Pet { Name = "Boots", Owner = terry }; //Pet whiskers = new Pet { Name = "Whiskers", Owner = charlotte }; //Pet daisy = new Pet { Name = "Daisy", Owner = magnus }; List<Person> people = new List<Person> { magnus, terry, charlotte }; //List<Pet> pets = new List<Pet> { barley, boots, whiskers, daisy }; List<Pet> pets = new List<Pet>(); // Create a list of Person-Pet pairs where // each element is an anonymous type that contains a // Pet name and the name of the Person that owns the Pet. var query = people.Join(pets, person => person, pet => pet.Owner, (person, pet) => new { OwnerName = person.Name, Pet = pet.Name }).ToList();
Guy Feb 08 '09 at 5:21 2009-02-08 05:21
source share