Fares Ayyad Fares Ayyad - 3 months ago 11
Ajax Question

Can I get the sum() using entity framework

I want to calculate the sum of a column
note that:column result showed as column in a table produced by calling stored proc with entity framework and AJAX

The code below show Web method that call the stored proc called divideTypes

if (ddlTer == "0")
{

var sp = db.divideTypes(dateFrom, dateTo, ddlType).ToList();
foreach (var u in sp)
{
result += "<tr>";
result += "<td>" + u.custid + "</td>";
result += "<td>" + u.custname + "</td>";
result += "<td>" + u.depno + "</td>";
result += "<td>" + u.Terr + "</td>";
result += "<td>" + u.deidate + "</td>";
result += "<td>" + u.gooddesc + "</td>";
result += "<td>" + u.custdec + "</td>";
result += "<td>" + u.pkg + "</td>";
result += "<td>" + u.wt + "</td>";
result += "<td>" + u.vwt + "</td>";
result += "<td>" + u.lcamt+ "</td>";
result += "<td>" + u.invno + "</td>";
result += "<td>" + u.invamt + "</td>";
result += "</tr>";
}

}


Note: I used to call stored proc because there's many join statement in SQL command so I cannot deal with it.

My question is how to get the sum of u.invmat column? (In any way)

Answer

You could just use the Sum method:

var sum = sp.Sum(d=>d.u.invmant);