I have a table. I grouped that table's rows. The columns are optional. Columns of the table: day, time, country, city, rain (millimeter). I would like to copy the solution to a new table.
Code:
var q = baseTable.AsEnumerable()
.GroupBy(row => columnsToGroupBy.Select(c => row[c]), comparer) //eg: day, time, country
.Select(group => new {
AllKeys = group.Key,
AllField = group.Sum(row => double.Parse(row["rain"].ToString()))});
Eg. after the grouping it shows how much rain has fallen.
q[0]: { AllKeys { "Tuesday, "06:00", "Austria" }, AllField { "1" } }
q[1]: { AllKeys { "Monday", "12:00", "Slovakia" }, AllField { "3" } }
q[2]: { AllKeys { "Tuesday, "06:00", "Slovakia" }, AllField { "1,5" } }
q[3]: { AllKeys { "Monday", "11:00", "Slovakia" }, AllField { "4" } }
I would like to sort by the keys in ascending order:
q[0] tartalma { AllKeys { "Monday", "11:00", "Slovakia" }, AllField { "4" } }
q[1] tartalma { AllKeys { "Monday", "12:00", "Slovakia" }, AllField { "3" } }
q[2] tartalma { AllKeys { "Tuesday, "06:00", "Austria" }, AllField { "1,5" } }
q[3] tartalma { AllKeys { "Tuesday, "06:00", "Slovakia" }, AllField { "1" } }
IF the user would like to change the sorting by the day and time, than it have to sort the columns to day and time. So this is not work, because I don't know how many keys will be:
var q2 = q.OrderBy(x => x.AllKeys.First()))
.ThenBy(x => x.AllKeys.ToList()[1]);
Can you help me, how to sort the query?