There is a table in a SQL database like below :
SampleTable :
-----------------------
id | number | price
-----------------------
1 | 3 | 300
2 | 1 | 200
3 | 5 | 100
4 | 10 | 10
5 | 30 | 30
6 | 1 | 500
-----------------------
I wanna calculate total price like below :
in each row => var SumOfEachRow = number * price;
Total Price = sum of SumOfEachRow;
Thus the Total Price
would be 3100.
Now , I wanna calculate it with LINQ. e.g :
int TotalPrice = from q in SampleTable
select new
{
TotalPrice = q.number * q.price
}.Sum();
the upside code returns the wrong result !!! Could you please guide me ? Thanks.