Marco Dinatsoli
Marco Dinatsoli

Reputation: 10590

c# databable how to sort this one

This is my code

var result = (from row in InBoundtable.AsEnumerable()
    where campains.Contains(row.Field<string>("Campaign"))
    group row by new
    {
      Date = row.Field<string>("Date"),
      Slice = row.Field<string>("Slice")
    } into grp
    select new
    {
      SL = grp.Sum((r) => Double.Parse(r["Inb.ServiceLevel"].ToString())) / grp.Count(),
      Date = ((DateTime.Parse(grp.Key.Date.ToString() + " " + grp.Key.Slice.ToString().Split('-')[0])) - epoch).TotalMilliseconds
    }).ToList();

how can I sort the result according to the Date column? from past to current

for example

Upvotes: 0

Views: 36

Answers (1)

Habib
Habib

Reputation: 223402

how can I sort the result according to the Date column? from past to current

Use OrderBy

var result = (from row in InBoundtable.AsEnumerable()
              where campains.Contains(row.Field<string>("Campaign"))
              group row by new
              {
                  Date = row.Field<string>("Date"),
                  Slice = row.Field<string>("Slice")
              } into grp
              select new
              {
                  SL = grp.Sum((r) => Double.Parse(r["Inb.ServiceLevel"].ToString())) / grp.Count(),
                  Date = ((DateTime.Parse(grp.Key.Date.ToString() + " " + grp.Key.Slice.ToString().Split('-')[0])) - epoch).TotalMilliseconds
              })
              .OrderBy(r=> r.Date) //HERE
              .ToList();

Upvotes: 3

Related Questions