Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sure, you're looking to perform a <em><a href="http://msdn.microsoft.com/en-us/library/bb918093.aspx" rel="nofollow">Full Outer Join</a></em> on the data, which doesn't exist in LINQ, so we fake it with two unioned Left Outer Joins:</p> <pre><code>var A = from a in List1 join b in List2 on new { a.Year, a.Month } equals new { b.Year, b.Month } into bgroup from b in bgroup.DefaultIfEmpty() select new { a.Year, a.Month, a.ValueA, ValueB = (b == null ? 0 : b.ValueB) }; var B = from b in List2 join a in List1 on new { b.Year, b.Month } equals new { a.Year, a.Month } into agroup from a in agroup.DefaultIfEmpty() select new { b.Year, b.Month, ValueA = (a == null ? 0 : a.ValueA), b.ValueB }; var List3 = A.Union(B); </code></pre> <p><em>Many apologies for the C#, I could not get my VB.Net example to work for the life of me. You need two left outer joins to be unioned to produce the correct answer. None of the code converters I tried worked either.</em></p> <hr> <p>The following is VB.Net that LINQPad chokes on, but every example I can find says should be correct:</p> <pre><code>Dim A = From a In List1 _ Group Join b In List2 _ On New With { a.Year, a.Month } Equals New With { b.Year, b.Month} _ Into bGroup = Group _ From b In bGroup.DefaultIfEmpty() _ Select a.Year, a.Month, a.ValueA, ValueB = If(b Is Nothing, 0, b.ValueB) Dim B = From b In List2 _ Group Join a In List1 _ On New With { b.Year, b.Month } Equals New With { a.Year, a.Month} _ Into aGroup = Group _ From a In aGroup.DefaultIfEmpty() _ Select b.Year, b.Month, ValueA = If(a Is Nothing, 0, a.ValueA), b.ValueB Dim List3 = A.Union(B) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload