c# - .SELECT statement using lambda and Entity Framework -
i struggling here in using .select
statement.
here snippet of code;
var payoutsperlocation = locations.select(l => l.payouts); foreach (var payouts in payoutsperlocation) { console.writeline(payouts.sum(pos=>pos.amount)); }
where in location list, , 1 location has 1 or more payout. want payouts.
the above code's result below
0 0 0 0 0 0
it should sum of amount of payouts per location. seems don't records of payout. when tried using code below (for testing if getting payout);
var payoutsperlocation = locations.firstordefault().payouts; foreach (var payout in payoutsperlocation) { console.writeline(payout.amout); }
there payout location. guys think doing wrong here?
any appreciated.
i don't know why it's giving zeros, shouldn't evaluate linq expressions inside foreach loop anyway. causes many round-trips database. try this:
var sumperlocation = locations.select(l => l.payouts.sum(p => p.amount)); foreach (var sum in sumperlocation) { console.writeline(sum); }
Comments
Post a Comment