1

This is my old code

DateTime epoch = new DateTime(1970, 1, 1);
var result = (from row in InBoundtable.AsEnumerable()
              group row by row.Field<string>("Date") into grp
              select new
              {
                  AbandonCalls = grp.Sum((r) => Double.Parse(r["AvgAbandonedCalls"].ToString())),
                  Date = ((DateTime.Parse(grp.Key.ToString())) - epoch).TotalMilliseconds
              }).ToList();

as you see, I am making group on Date column.

Can I make the group on Date and Slice columns? where both of them is string value

1 Answer 1

1

Create an anonymous type using those two columns. Both columns will be part of the group's "key", so you'll have to access them separately.

DateTime epoch = new DateTime(1970, 1, 1);

var result = (from row in new DataTable().AsEnumerable()
              group row by new
                           {
                               Date = row.Field<string>("Date"),
                               Slice = row.Field<string>("Slice")
                           }
              into grp
              select new
                     {
                         AbandonCalls = grp.Sum((r) => Double.Parse(r["AvgAbandonedCalls"].ToString())),
                         Date = ((DateTime.Parse(grp.Key.Date)) - epoch).TotalMilliseconds,
                         grp.Key.Slice
                     }).ToList();
Sign up to request clarification or add additional context in comments.

4 Comments

why did you remove the into grp part please?
could you please? because you have added new {} which is a new syntax to me
I tried this }into grp and no syntax error. I am testing the results
sorry for being late, i have other problems, I will update you as soon as possible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.