I am creating an timesheet app, I would like to display following:
For each employee into a grid:
Id, Name, TaskName, SunHours, MondayHours... and so on FridayHours
Employee_Table
empid
name
Timesheet
id
empid
taskid
sat
sun
mon
tues
wed
thurs
fri
sat
Task
taskid
taskname
I am struggling to create the object from a linq query as I cannot access the timesheet specific data i.e sun, mon, tue values. Here is what I have done:
var result = (from e in db.Employees
join t in db.TimeSheets on e.Id equals t.EmployeeId
group e by t.TaskId into g
orderby g.Key
select new
{
empid = g.Key,
name = g.Select(e => e.Name),
sat = g.Select(s => s.Saturday), // cannot access this info
sun = g.Select(s => s.Sunday),
mon = g.Select(s => s.Monday),
tue = g.Select(s => s.Tuesday),
wed = g.Select(s => s.Wednesday),
thurs = g.Select(s => s.Thursday),
fri = g.Select(s => s.Friday),
});
Update:
So, I have ended up with this - it seems to represent what I am after.
var res = (from e in db.Employees
join t in db.TimeSheets on e.Id equals t.EmployeeId
group t by new { t.EmployeeId } into g
select new
{
id = g.Key.EmployeeId,
data = g
});