title: DataTable Error - Can't CopyToDataTable()
body: <p>Suppose I have the following 2 datatables:</p>
  
  <pre><code>Table1:                               Table2:
  Col1:                                 Col1:         Col2:
  1                                     1             a
  2                                     2             b
  2                                     3             c
  3                                     4             d
  3                                     5             e
  4                                     6             f
                                        7             g
  </code></pre>
  
  <p>And I want a simple Linq query that creates a third DataTable based upon a join between the two and giving distinct values - Looking as follows:</p>
  
  <pre><code>Result:
  Col1:       Col2:
  1           a
  2           b
  3           c
  4           d
  </code></pre>
  
  <p>I assumed this would do it:</p>
  
  <pre><code>Dim Result as DataTable = (From dr1 As DataRow In Table1.AsEnumerable
               Join dr2 As DataRow In Table2.AsEnumerable
               On dr1.Field(Of Double)("Col1") Equals dr2.Field(Of Double)("Col1")
               Select New With {
                                   .Col1 = dr1.Field(Of Double)("Col1"),
                                   .Col2 = dr2.Field(Of String)("Col2")
                               }).Distinct.CopyToDataTable
  </code></pre>
  
  <p>But I'm getting a host of different errors regardless what I try...</p>
  
  <p>My first error is that <code>CopyToDataTable</code> method is not a member of <code>System.Generic.IEnumerable</code></p>
  
  <p>When I remove that, and leave it as:</p>
  
  <pre><code>Dim Result = (From dr1 As DataRow In Table1.AsEnumerable
               Join dr2 As DataRow In Table2.AsEnumerable
               On dr1.Field(Of Double)("Col1") Equals dr2.Field(Of Double)("Col1")
               Select New With {
                                   .Col1 = dr1.Field(Of Double)("Col1"),
                                   .Col2 = dr2.Field(Of String)("Col2")
                               }).Distinct
  </code></pre>
  
  <p>It runs, but it doesn't filter the results down to a unique list - It leaves all the <code>col1</code> values in there from <code>Table1</code>.</p>
  
  <p>I'm trying to understand Linq, but am obviously missing something - Can someone please explain to me what's going on here and how to fix this??</p>
  
  <hr>
  
  <p>As an addition onto @Magnus' solution, for anyone who comes across this kind of problem in the future, the <code>CopyToDataTable</code> method for an IEnumerable of Anonymous Type (as Magnus pointed out was what I gave in this question) can be found <a href="http://msdn.microsoft.com/en-us/library/bb669096.aspx" rel="nofollow">here</a> and an implementation of it <a href="http://msdn.microsoft.com/en-us/library/bb386921.aspx" rel="nofollow">here</a>.</p>