class ExpenseClaim
{
int EmployeeId;
int Team;
double Cost;
}
List<EmployeeExpense> GetEmployeeExpenses()
{
return _expenseClaims
.GroupBy(e => e.EmployeeId)
.Select(x =>
new EmployeeExpense(
x.Key,
x.Sum(e => e.Cost)
);
}
Sorry pretty far-fetched example.
How do I get an employee team in GetEmployeeExpenses? I guess I need a second group, but I can't parse the syntax.
Please note that for this employee they Teamwill always be the same anyway, so I’m happy to take Team, for example, the first grouped by record.
So...
ExpenseClaim { EmployeeId = 1, Team = Sales, Cost = 100 }
ExpenseClaim { EmployeeId = 1, Team = Sales, Cost = 50 }
=>
EmployeeExpense { EmployeeId = 1, Team = Sales, Cost = 150 }
source
share