title: How to sort datatable and keep primary keys?
body: <p>I have a datatable (dt) with 6 columns (S1, S2, S3 are <code>string</code> and D1, D2, D3 are <code>double</code>). The combination of the <code>string</code> columns (S1, S2, S3) make up my PrimaryKey:</p>
  
  <pre><code>dt.PrimaryKey = new DataColumn[] 
  { dt.Columns["S1"], dt.Columns["S2"], dt.Columns["S3"] };
  </code></pre>
  
  <p>Now, I want to sort dt by D1, D2, D3 and save it as a datatable.
  Here is what I got:</p>
  
  <pre><code>DataView view = new DataView(dt);
  view.Sort = "D1, D2, D3";
  dt = view.ToTable();
  </code></pre>
  
  <p>The problem is dt is sorted the way I wanted by I lost my PrimaryKeys. I tried to replace the 3rd line with <code>dt = view.Table.Copy();</code> which keeps the PrimaryKeys but the sort won't work. I also tried using <code>LINQ</code> (<a href="https://stackoverflow.com/questions/20204590/how-to-sort-datatable-based-on-multiple-column">How to sort DataTable based on multiple column?</a>) and checked this trend (<a href="https://stackoverflow.com/questions/1208548/datatable-defaultview-sort-doesnt-sort">DataTable.DefaultView.Sort Doesn&#39;t Sort</a>) but none of them worked.</p>
  
  <p>Am I doing something wrong? Any help is much appreciated.</p>