title: Dynamically adding the columns in group by clause of linq
body: <p>I am getting a datatable from service. I am using linq to calculate of sum new columns. I want all the coumns in datatable originally plus the new columns calculated in linq. </p>
  
  <p>Problem is columns in datatable are not fixed. How would I dynamically add the columns in select clause of linq.</p>
  
  <p>Below is code snippet: </p>
  
  <pre><code>DataTable dt = ds.Tables[0];
  var orderCtr =
  from o in dt.AsEnumerable()
  where o.Field&lt;string&gt;(Constants.GENDER_NAME) != "Unknown"
  group o by new
  {
                      odr_id = o.Field&lt;int&gt;(Constants.ORDER_ID),
                      //NEED TO ADD COLUMNS DYNAMICALLY HERE. MEANS IF THEY ARE IN DATATABLE.
                  }
                      into g
                      select new
                      {
                           //NEED TO ADD COLUMNS DYNAMICALLY HERE. MEANS IF THEY ARE IN DATATABLE.
                          odr_id = g.Key.odr_id,
                          ac_gr_imp = g.Sum(r =&gt; r.Field&lt;long&gt;(Constants.GENDER_IMPRESSION)),
                          ac_gr_clk = g.Sum(r =&gt; r.Field&lt;long&gt;(Constants.GENDER_CLICK)),
                          Ctr = (double)g.Sum(r =&gt; r.Field&lt;long&gt;(Constants.GENDER_IMPRESSION)) / g.Sum(r =&gt; r.Field&lt;long&gt;(Constants.GENDER_CLICK)),
                      };
  </code></pre>