Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 21, 2012 01:56 PM by vahid bakkhi
Member
22 Points
54 Posts
May 21, 2012 11:36 AM|LINK
Hi
I have the following codes
var nolHistorySummary = dtGridDetails.AsEnumerable() .GroupBy(x => new { Id = x.Field<string>("Id") }) .Select(groupedTable => new { Id = groupedTable.Key.Id, Prev = groupedTable.Sum(s => Convert.ToDecimal(s.Field<string>(col1))), Adj = groupedTable.Sum(s => Convert.ToDecimal(s.Field<string>(col2))) });
now i need to assign the "nolHistorySummary " value to a list or datatable.how itsd possible
Star
12213 Points
1830 Posts
May 21, 2012 11:45 AM|LINK
Try following:
var myList = nolHistorySummary.ToList();
341 Points
304 Posts
May 21, 2012 01:56 PM|LINK
you can create a class below like :
class myClass { public string Id { get; set; } public string Prev { get; set; } public string Adj { get; set; } }
and then use of below like :
List<myClass> nolHistorySummary = dtGridDetails.AsEnumerable() .GroupBy(x => new { Id = x.Field<string>("Id") }) .Select(groupedTable => new { Id = groupedTable.Key.Id, Prev = groupedTable.Sum(s => Convert.ToDecimal(s.Field<string>(col1))), Adj = groupedTable.Sum(s => Convert.ToDecimal(s.Field<string>(col2))) });
ajeesh.mekka...
Member
22 Points
54 Posts
How to assign Linq group by value to a List
May 21, 2012 11:36 AM|LINK
Hi
I have the following codes
var nolHistorySummary = dtGridDetails.AsEnumerable()
.GroupBy(x => new
{
Id = x.Field<string>("Id")
})
.Select(groupedTable => new
{
Id = groupedTable.Key.Id,
Prev = groupedTable.Sum(s => Convert.ToDecimal(s.Field<string>(col1))),
Adj = groupedTable.Sum(s => Convert.ToDecimal(s.Field<string>(col2)))
});
now i need to assign the "nolHistorySummary " value to a list or datatable.how itsd possible
urenjoy
Star
12213 Points
1830 Posts
Re: How to assign Linq group by value to a List
May 21, 2012 11:45 AM|LINK
Try following:
var myList = nolHistorySummary.ToList();
vahid bakkhi
Member
341 Points
304 Posts
Re: How to assign Linq group by value to a List
May 21, 2012 01:56 PM|LINK
you can create a class below like :
class myClass { public string Id { get; set; } public string Prev { get; set; } public string Adj { get; set; } }and then use of below like :
List<myClass> nolHistorySummary = dtGridDetails.AsEnumerable() .GroupBy(x => new { Id = x.Field<string>("Id") }) .Select(groupedTable => new { Id = groupedTable.Key.Id, Prev = groupedTable.Sum(s => Convert.ToDecimal(s.Field<string>(col1))), Adj = groupedTable.Sum(s => Convert.ToDecimal(s.Field<string>(col2))) });