有幾個關於LIN已經有關於LINQ樞軸的問題,雖然其中有幾個概述了我的確切問題,但我無法成功地將它們轉換爲工作解決方案。我覺得這主要是由於我加入了我的桌子。另一個LINQ樞軸問題 - 將SQL腳本轉換爲LINQ
因此,爲了所有LINQ愛好者都喜歡的問題,這裏有另一個難題讓你解決問題。請幫我(和掙一些信譽分,離我很尊重)下面的SQL存儲過程腳本轉換爲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
非也!只有一個問題 - 我需要一週中的每一天而不是數。但是這絕對是答案,但是這個例外。下一條評論包含例外情況。 – 2008-12-08 09:19:03
System.Collections.Generic.IEnumerable不包含「Sum」的定義和最佳擴展方法重載「System.Linq.Enumerable.Sum(System.Collections.Generic.IEnumerable )」有一些無效論據 –
2008-12-08 09:20:21