title: Linq to Compare two datatables and Filter data
body: <p>I have two  dataTables ,</p>
  
  <pre><code>     Id     Name
        1     Alex
        2     Hiro
  </code></pre>
  
  <p>and my second datatable is </p>
  
  <pre><code>      Field   |  1   |  1_Value  |  2     |  2_Value
        Salary  | 123.4|  Good     |  245   |  Bad
        CTC     | 25.4 |  Bad      |  300   |  good
  </code></pre>
  
  <p>First Table Id values 1, 2 are  the column of second table.
  I wanna compare both table using the Id - column relation  using linq and my expected filtered output should look like</p>
  
  <pre><code>      [{
          "Id" : 1 , "Name": "Alex",
           "data" : [123.4, 25.4] ,"values":["Good" ,"Bad"]},
          {
          "Id" : 2 , "Name": "Hiro",
           "data" : [245, 300] ,"values":["Bad","Good" ]}
          ]
  </code></pre>
  
  <p>My Code try is using foreach loops like</p>
  
  <pre><code>        if (ds.Tables[1].Rows.Count &gt; 0)
                  {
                      var comparisonDetail = (from DataRow dataRow in ds.Tables[1].Rows
                                              select new cls.MyBaseClass()
                                              {
                                                  ID = Convert.ToInt64(dataRow["ID"]),
                                                  Name= Convert.ToString(dataRow["Name"])  
                                              }
  
                                              ).ToList();
                      foreach (var vId  in  comparisonDetail)
                      {
                         foreach(var vRow in ds.Tables[2].Rows)
                         {
              vId.Data = vRow.value.
  
                         } 
                      }
  </code></pre>
  
  <p>How can I acheive this using c# linq?
  Help would be appreciated</p>