public void JoinWithThisAsKeyTuple() { BasicPerson magnus = new BasicPerson { Name = "Hedlund, Magnus" }; BasicPerson terry = new BasicPerson { Name = "Adams, Terry" }; BasicPerson charlotte = new BasicPerson { 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 <BasicPerson> people = new List <BasicPerson> { magnus, terry, charlotte }; List <Pet> pets = new List <Pet> { barley, boots, whiskers, daisy }; // Create a list of Person-Pet pairs where // each element is an anonymous type that contains a // Pet's name and the name of the Person that owns the Pet. var answer = people.Join <BasicPerson, Pet, BasicPerson, Tuple <string, string> >(pets, person => person, pet => pet.Owner, (person, pet) => new Tuple <string, string>(person.Name, pet.Name)); var result = people.Query <BasicPerson, Pet, Tuple <string, string> >("SELECT this.Name AS OwnerName, that.Name AS PetName FROM this INNER JOIN that ON this = that.Owner", pets); Assert.IsTrue(result.Any()); Assert.IsTrue(answer.Any()); Assert.IsTrue(result.SequenceEqual(answer)); }
public void JoinWithThisAsKeyTuple() { BasicPerson magnus = new BasicPerson { Name = "Hedlund, Magnus" }; BasicPerson terry = new BasicPerson { Name = "Adams, Terry" }; BasicPerson charlotte = new BasicPerson { 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<BasicPerson> people = new List<BasicPerson> { magnus, terry, charlotte }; List<Pet> pets = new List<Pet> { barley, boots, whiskers, daisy }; // Create a list of Person-Pet pairs where // each element is an anonymous type that contains a // Pet's name and the name of the Person that owns the Pet. var answer = people.Join<BasicPerson, Pet, BasicPerson, Tuple<string, string>>(pets, person => person, pet => pet.Owner, (person, pet) => new Tuple<string, string>(person.Name, pet.Name)); var result = people.Query<BasicPerson, Pet, Tuple<string, string>>("SELECT this.Name AS OwnerName, that.Name AS PetName FROM this INNER JOIN that ON this = that.Owner", pets); Assert.IsTrue(result.Any()); Assert.IsTrue(answer.Any()); Assert.IsTrue(result.SequenceEqual(answer)); }