Alex Rivera | Logout

IEnumerable<T> to a CSV file

Asked 2011-06-01T10:22:07.503
16

I am getting the result from LINQ query as var of type IEnumerable<T>

I want a CSV file to be created from the result from the LINQ

I am getting the result from the following query

var r = from table in myDataTable.AsEnumerable()
        orderby table.Field<string>(para1)
        group table by new { Name = table[para1], Y = table[para2] }
        into ResultTable
        select new
        {
            Name = ResultTable.Key,
            Count = ResultTable.Count()
        };
Edit
Report

1 Answer

2

its not clear what you realy want, but this can be a solution public void Read() {

    var r = from table in myDataTable.AsEnumerable()
            orderby table.Field<string>(para1)
            group table by new { Name = table[para1], Y = table[para2] }
                into ResultTable
                select new NameCount()
                {
                    Name = ResultTable.Key,
                    Count = ResultTable.Count()
                }.ToString();

    //Write all r to a File
}
public class NameCount
{
    public string Name { get; set; }
    public int Count { get; set; }
    public string ToString()
    {
        return string.Format("{0},{1}\r\n", Name, Count);
    }
}
answered 2011-06-01T12:42:15.167

Your Answer