There are two types of LINQ groupings, one is table grouping summary and the other is list<> grouping totals. The following examples illustrate two groups of subtotals.
first, group totals for tables:
DataTable table = new DataTable ();
Table. Columns.Add ("Column name 1", Type.GetType ("System.Int32"));
Table. Columns.Add ("Column Name 2", Type.GetType ("System.Int32"));
Table. Columns.Add ("Column name 3", Type.GetType ("System.String"));
Table. Columns.Add ("Column name 4", Type.GetType ("System.String"));
Table. Columns.Add ("Column name 5", Type.GetType ("System.String"));
Table. Columns.Add ("Value or Amount column name", Type.GetType ("System.String"));
Assigning Values to table tables
......
GROUP by [column name 2]
var dtsummary = from Q in table. AsEnumerable ()
Group Q by new {column name 2= q.field<int> ("Column Name 2")} into G
Select New
{
Column name 2= g.key. Column Name 2,
Value or amount summary column name = G.sum (a => a.field<decimal> ("Value or Amount column name")
};
The second type of,list<> group rollup:
var listsummary = from P in list< entity >
Group p by new {Property 1 = P. Property 1} into G
Select New
{
Property 1 = G.key. Property 1,
Sum of value or amount = G.sum (a => a. numeric or amount attribute)
};