There are several questions about SO already regarding LINQ pivots, and although some of them describe my exact problem, I cannot successfully translate them into a working solution. I feel this is mainly due to connecting to my tables.
So in the interests of all LINQ addicts who love the problem, here's another mystery for you. Please help me (and earn me some reputation points and a lot of respect) by translating the following SQL-stored proc script into LINQ:
ALTER PROCEDURE [dbo].[GetTimesheetForWeekById] @timesheetid int, @begindate VarChar(20), @enddate VarChar(20) AS BEGIN SELECT T.TaskName, SUM( case DATEPART(weekday, TE.StartTime) WHEN 1 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END ) AS Sunday, SUM( case DATEPART(weekday, TE.StartTime) when 2 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END ) AS Monday, SUM( case DATEPART(weekday, TE.StartTime) when 3 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END ) AS Tuesday, SUM( case DATEPART(weekday, TE.StartTime) when 4 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END ) AS Wednesday, SUM( case DATEPART(weekday, TE.StartTime) when 5 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END ) AS Thursday, SUM( case DATEPART(weekday, TE.StartTime) when 6 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END ) AS Friday, SUM( case DATEPART(weekday, TE.StartTime) when 6 THEN DATEDIFF(minute, TE.StartTime, TE.EndTime) ELSE 0 END ) AS Saturday FROM Tasks T INNER JOIN TimeEntries TE on T.TaskID = TE.TaskID WHERE TE.StartTime BETWEEN (CONVERT(datetime, @begindate, 103)) AND (CONVERT(datetime, @enddate, 103)) AND TE.TimesheetID = @timesheetid GROUP BY T.TaskName END