Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sum 2 Columns in Linq

I am trying to sum two columns that i have in LINQ. The following is my LINQ statement

var SigmaGood =  from n in db.tbl_dppITHr
                 where n.ProductionHour >= SelectedDateDayShiftStart
                 where n.ProductionHour <= SelectedDateEnd
                 select n.part1 + n.part2

ViewData["GoodTotal"] = SigmaGood.Sum();

I am trying to get a total for part1 + part2;

When i try and test the result i dont get any value back i get a blank.

Anyone any ideas what i am doing incorrect?

enter image description here

like image 314
Inkey Avatar asked Nov 12 '22 20:11

Inkey


1 Answers

I would say blank must mean the key you're storing the value against doesn't match the key you are reading/displaying. If it did you would at least see 0, not blank.

Do it in two steps and debug it.

var total = sigmaGood.Sum();
ViewData["GoodTotal"] = total; //breakpoint on this line and check value of total.

Or hardcode a test value, I bet it still comes out blank:

ViewData["GoodTotal"] = 1234;
like image 199
weston Avatar answered Nov 14 '22 22:11

weston