I have the following block of linq queries to calculate some values for a report.
var items = (from trans in calclabordb.Sales_Transactions
select trans).SelectMany(st => st.Sales_TransactionLineItems).Where(stli => stli.TypeID == typeID);
decimal test = items.Where(stli => stli.Inventory_Item is Base).Sum(stli => (decimal?)stli.Inventory_Item.IntExtraServiceAmount) ?? 0;
decimal test2 = items.Where(stli => stli.Inventory_Item is Extra).Sum(stli => (decimal?)stli.ItemPrice) ?? 0;
decimal test3 = test + test2;
current.ExtraSales = items.Where(stli => stli.Inventory_Item is Base).Sum(stli => (decimal?)stli.Inventory_Item.IntExtraServiceAmount) ?? 0 +
items.Where(stli => stli.Inventory_Item is Extra).Sum(stli => (decimal?)stli.ItemPrice) ?? 0;
I've stepped through the code in a debugger and I've noticed some oddities. After assigning into test
its value is 0. After assigning into test2
test2 == 0
and test == 11.31
after assigning into test3 test == 11.31
test2 == 11.28
and test3 == 22.59
after assigning into ExtraSales
ExtraSales == 11.31
. The value in ExtraSales
when this is all complete should be 22.59. What's going on here?
EDIT: I've added additional lines after the assignment into ExtraSales
but the value does not change.