0

This is my 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)) - epoch).TotalMilliseconds
                         }).ToList();

where InBoundtable is a datatable.

now I have a string array campains

my question is there a way so in the select statement above I can make where the campain field, which is a string field, is either one of the values in the campains array?

1 Answer 1

1

You can use Enumerable.Contains("campain value"):

var query =  from row in InBoundtable.AsEnumerable()
             where campains.Contains(row.Field<string>("Campain"))
             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)) - epoch).TotalMilliseconds
             };
var result = query.ToList();
Sign up to request clarification or add additional context in comments.

4 Comments

@MarcoDinatsoli: note that i've edited the answer since you should exclude rows before the group by.
that is what I was going to ask you about. I am trying it
if the array of string is empty, will that code throw exception? or just empty result?
@MarcoDinatsoli: it won't throw an exception if it's empty, only if it's null. Read: msdn.microsoft.com/en-us/library/bb352880(v=vs.100).ASPX

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.