I am using aggregate function in SQL query and I want the result in linq to sql.
My Query is :
string sql = "Select sum(e.Salary) as 'TotalSalary' from Employee e";
and I am using LinqToSql to get the TotalSalary.
IEnumarable result = DBContext.ExecuteQuery(sql);
How can I get the “TotalSalary” from result?
If you are using Linq2Sql, you could simply do:
Or, using the custom SQL approach, this is how it could work:
(adjust
decimalto your actual data type if needed)