How to group by tables in datatable and sum them using ER

Jan 19 2018 2:04 AM
I am a newbie here and I have an issue: I have 5 tables in my database with the same columns and headers, so I want to group by all the tables and I want to sum them.
 
Suppose if there is a column Amount which is present in all 5 tables, then I want to group by the Amount and I want to sum all the 5 table values using Entity Framework.
 
This is my code which I'm using to do group by, but I'm unable to do the sum:
  1. private DataTable ProcessData(DataSet ds)  
  2. {  
  3. DataTable dt = new DataTable();  
  4. dt = ds.Tables[0].AsEnumerable()  
  5. .GroupBy(r => new { Col1 = r["Name"], Col2 = r["Amt"], Col3 = r["Net"], Col4 = r["Data"] })  
  6. .Select(g => g.OrderBy(r => r["max"]).First())  
  7. .CopyToDataTable();  
  8. return dt;  
  9. }

Answers (1)