title: C# lambda-> All rows Select Add Row_Number
body: <p>I have a table: </p>
  
  <pre><code>DataTable store_temp = new DataTable(); 
  store_temp.Columns.Add("patn");
  store_temp.Columns.Add("rf");
  store_temp.Columns.Add("name");
  store_temp.Columns.Add("conv");
  store_temp.Columns.Add("conv_type");
  store_temp.Columns.Add("recorddate");
  store_temp.Columns.Add("executiondate");
  </code></pre>
  
  <p>My C# code :</p>
  
  <pre><code>int i = 0;
  var rowsgroups = (from row in store_temp.AsEnumerable().GroupBy(row =&gt;
  row.Field&lt;string&gt;("patn"))
  .OrderBy((g =&gt; g.OrderByDescending(y =&gt; y.Field&lt;string("executiondate")).ThenByDescending(y =&gt;
  y.Field&lt;string&gt;("rf"))))
  select new
  {
      patn = row.ElementAt(i),
      rf_num = ++i,
  }).ToArray();
  </code></pre>
  
  <p>I want the lambda experession, which is equivalent to: </p>
  
  <blockquote>
    <blockquote>
  <pre><code>select patn, rf,
  </code></pre>
      
      <p><strong>>     row_number() over( partition by  patn order by  executiondate,rf ) 
      as rf_num,</strong></p>
    </blockquote>
  
  <pre><code>     name, conv,conv_type, recorddate, executiondate 
        from store_temp2
  </code></pre>
  </blockquote>
  
  <p><strong>But, lambda syntax  ... var rowsgroups has just a one row..
  I want to show  all rows in store_temp.
  What should I do to fix the query?</strong></p>