0
我見從我試圖轉換爲LINQ到SQL語句如下:內有多個左外連接連接
FROM mc.WORKORDER AS wo WITH (NOLOCK)
INNER JOIN mc.WORKTASK AS wt WITH (NOLOCK)
ON wo.wordoi = wt.wrkord_oi
AND wo.tmplt = 0
AND wo.ci_cnc_date IS NULL
AND wt.ci_cnc_date IS NULL
AND wt.clsdt_date >= CAST('1/1/' + CAST(year - 1 AS varchar) AS DateTime)
AND wt.clsdt_date < DATEADD("mm", 1, CAST(CAST(quarter * 3 AS varchar) + '/1/' + CAST(year AS varchar) AS DateTime))
LEFT OUTER JOIN mc.WOLABOR AS wol WITH (NOLOCK)
ON wt.wtskoi = wol.wt_oi
LEFT OUTER JOIN mc.CREW AS c WITH (NOLOCK)
ON wt.crew_oi = c.crewoi
LEFT OUTER JOIN mc.WORKORDERTYPE AS wot WITH (NOLOCK)
ON wt.wot_oi = wot.wotyoi
LEFT OUTER JOIN mc.SEGMENTEDACCOUNT AS sa WITH (NOLOCK)
ON wt.segacctref_oi = sa.sgaccoi
LEFT OUTER JOIN mc.SEGVALUE AS sv WITH (NOLOCK)
ON sa.segval4ref_oi = sv.sgvaloi
LEFT OUTER JOIN mc.PRIORITY AS p WITH (NOLOCK)
ON wo.prio_oi = p.priooi
LEFT OUTER JOIN mc.SITE AS s WITH (NOLOCK)
ON wo.BEparn_oi = s.siteoi
所以我開始我的翻譯是這樣的:
int year = 2012, quarter = 1;
string monthYear = "1/1";
DateTime closeDate = new DateTime(monthYear, (year-1));
DateTime timeframe = new DateTime(year, (quarter * 3), 01).AddMonths(1);
var allWorkorders =
(from wo in WORKORDERs
join wt in WORKTASKs on wo.Wordoi equals wt.Wrkord_oi && wo.Tmplt equals 0 && wo.Ci_cnc_date == null && wt.ci_cnc_date == null &&
wt.clsdt_date >= (string)closeDate && wt.clsdt_date < timeframe
現在從這裏我試圖直接進入第一個左外連接。但是,編譯器告訴我在時間結束時需要分號。
我還可以在var allWorkOrders中完成其他連接,還是必須創建一個新連接?
你可能會考慮到這嘗試的實驗[LINQPad(http://www.linqpad.net/)已經不是很有用的工具了。 –
爲什麼麻煩翻譯它呢?將它推入視圖或表值UDF中,並將其顯示爲「IQueryable」以啓用查詢組合。 – bluevector
@達思大陸 - LINQPad是我使用的。 –