Linq query: append column to query results

Posted by jrubengb on Stack Overflow See other posts from Stack Overflow or by jrubengb
Published on 2011-01-12T17:34:07Z Indexed on 2011/01/12 17:54 UTC
Read the original article Hit count: 205

Filed under:
|
|
|

I am trying to figure out how to append a column to Linq query results based on the max value of the query. Essentially, I want to create an EnumerableRowCollection of DataRows that would include a max value record with the same value for each record. So if i have a hundred records returned through the query, I want to next calculate the max value of one of the fields, then append that max value to the original query table:

DataTable dt = new DataTable();
dt = myDataSet.myDataTable;

EnumerableRowCollection<DataRow> qrySelectRecords =
          (from d in dt.AsEnumerable()
           where d.Field<DateTime>("readingDate") >= startDate && g.Field<DateTime>("readingDate") <= endDate
           select d);

Here's where I need help:

double maxValue = qrySelectRecords.Field<double>("field1").Max();

foreach (DataRow dr in qrySelectRecords)
{
 qrySelectRecords.Column.Append(maxValue)
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET