Full Outer Join

Practical example

The examples above have a simple data structure so you can focus on understanding the different LINQ joins technically, but in the real world you would have tables with columns you need to join.

In the following example, there is just one class Region used, in reality you would join two or more different tables which hold the same key (in this example first and second are joined via the common key ID).

You can see that in this example first doesn’t contain any region descriptions so you want to join them from second. Then the inner join would look like:

// do the inner join
varresult=fromfinfirstjoinsinsecondonf.IDequalss.IDselectnew{f.ID,s.RegionDescription};

// Result: {1,"Eastern"}
// {3, Northern}
// {4,"Southern"}

This result has created anonymous objects on the fly, which is fine, but we have already created a proper class - so we can specify it: Instead of select new { f.ID, s.RegionDescription }; we can say select new Region(f.ID, s.RegionDescription);, which will return the same data but will create objects of type Region - that will maintain compatibility with the other objects.