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:
- private DataTable ProcessData(DataSet ds)
- {
- DataTable dt = new DataTable();
- dt = ds.Tables[0].AsEnumerable()
- .GroupBy(r => new { Col1 = r["Name"], Col2 = r["Amt"], Col3 = r["Net"], Col4 = r["Data"] })
- .Select(g => g.OrderBy(r => r["max"]).First())
- .CopyToDataTable();
- return dt;
- }