Linq query: append column to query results
- by jrubengb
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)
}