I’m trying to create a query that groups by a field in the first table, sums a first table field, and includes a single field from a second. I keep getting an error when attempting to refer to a field from the joined table.
Table1: Users
Id
DisplayName
Table2: TimeEntries
WeekEnding
UserId
Hours
Query:
from u in Users
join t in TimeEntries on u.Id equals t.UserId
group t by new {t.WeekEnding, t.UserId } into g
select new {WE = g.Key.WeekEnding, User = g.Key.UserId,
HoursTotal = g.Sum(s => s.Hours), DisplayName = g.First(n => n.DisplayName)}
I’ve tried many things but “DisplayName” is not a valid field.
Any help on this will be greatly appreciated. Thank you.
Here’s a couple options.