Thursday, November 12, 2009

LINQ DataTable Query - Group Aggregation

var  query = from  row in  dtInvoice.AsEnumerable()
    group  row by   new  { InvNo =  row.Field< string >( "InvNo" ),
    EmpUNID = row.Field< decimal >( "EmployeeUNID" )} into  grp                        
    orderby  grp.Key.InvNo
        select new
        {                           
            Key =  grp.Key,  
            InvNo = grp.Key.InvNo,
            EmpID = grp.Key.EmpUNID,                                                           
            TotalCost = grp.Sum(r => r.Field< decimal >( "TotalCost" )),
            TotalRev = grp.Sum(r => r.Field< decimal >( "TotalRev" ))
        };

No comments:

Post a Comment

Followers

Search This Blog