title: Group and Order Dataset
body: <h2>Background</h2>
  
  <p>I have a dataset with lots of repeating values, which have come from a CSV file.</p>
  
  <p>I know how I would group, sort and add a count if the data was in a database using SQL.</p>
  
  <p><strong>SQL</strong></p>
  
  <pre><code>SELECT pass, count(pass)
  FROM table
  GROUP BY pass
  ORDER BY pass, count(pass) ASC
  </code></pre>
  
  <p>I've attempted to do this using LINQ.</p>
  
  <h2>What I've Tried?</h2>
  
  <pre><code>//Sort
         dtData.DefaultView.Sort = "Pass";
         dtData = dtData.DefaultView.ToTable();
  
   //Group
          dtData = dtData.AsEnumerable()
         .GroupBy(r =&gt; new { Col1 = r["Pass"] })
         .Select(g =&gt; g.OrderBy(r =&gt; r["Pass"]).First())
         .CopyToDataTable();
  </code></pre>
  
  <p><strong>However I need a extra column called count, else the group is pointless. How can i get an extra column with a count?</strong> </p>
  
  <p>Note: To the person who flagged this question as a duplicate of the below question, please see remark above. The flagged question is just how to sort dataset.</p>
  
  <p><a href="https://stackoverflow.com/questions/9107916/sorting-rows-in-a-data-table">Sorting rows in a data table</a></p>