I cannot seem to figure out how to do a full outer join in Linq using lambda expressions. Here is a stripped down sample of what I'm trying to do.
void Main()
{
var myPets = new List<petInfo>();
var yourpets = new List<petInfo>();
myPets.Add(new petInfo("me", "dog","Rex"));
myPets.Add(new petInfo("me", "fish","Goldy"));
myPets.Add(new petInfo("me", "iguana","Spikey"));
yourpets.Add(new petInfo("you", "dog","Spot"));
yourpets.Add(new petInfo("you", "cat","Tigger"));
yourpets.Add(new petInfo("you", "bird","Polly"));
var ourPets = myPets.GroupJoin(yourpets, mine => mine.PetType, yours => yours.PetType, (mine, yours) => new { WHAT GOES HERE???});
}
where petInfo is a boring class:
public class petInfo
{
public string Owner;
public string PetType;
public string PetName;
public petInfo(string owner, string petType, string petName)
{
Owner = owner;
PetType = petType;
PetName = petName;
}
}
I'm expecting ourPets to have the following records after the outer join:
PetType MyOwnerName MyPetName YourOwnerName YourPetName
bird you Polly
cat you Tigger
dog me Rex you Spot
fish me Goldy
iguana me Spikey
I've figured out almost everything else with linq and lambda, but for some reason joins are causing me all sorts of grief. I usually wind up just looping over the two sets and creating a third manually, but I've decided I want to solve this once and for all. All of the examples I found here seem to be a bit off or have requirements specific to this problem. I haven't found a good basic lambda outer join yet.
edit I have looked at the referenced solution and would like to implement this without using an extension method if possible. If it isn't possible, then I'll do so, but I love linq and lambda's because the code is so clean and it just feels like this should be able to be accomplished in a much simpler manner.