2011-04-06 241 views
0

有人可以幫助將以下內容轉換爲LINQ To SQL查詢嗎?將SQL轉換爲LINQ To SQL語句

select * from projects pr 
where pr.Active<>0 
AND CapturedDocumentType=2 
AND SubmissionReminderTypeID > 0 
AND pr.ProjectID In(SELECT Max(wpr.ProjectID) as ProjID 
        FROM Projects wpr 
        where wpr.Active<>0 
        AND wpr.CapturedDocumentType=2 
        AND wpr.SubmissionReminderTypeID > 0 
        group by wpr.EmployeeID) 
+0

在這個查詢,你不需要第3 where條件。你已經在你的嵌套查詢中檢查了。 – 2011-04-07 15:23:00

回答

1

試試這個

var result = from pr in dc.Projects 
      where 
       (from wpr in dc.Projects 
       where wpr.Active && 
         wpr.CapturedDocumentType == 2 && 
         wpr.SubmissionReminderTyepID > 0 
       group wpr by wpr.EmployeeID into gpr 
       select gpr.Max(x => x.ProjectID)).Contains(pr.ProjectID) 
      select pr; 
+0

我在這部分gpr.Max(ProjectID)中獲取ProjectID不存在於上下文中。 – Malcolm 2011-04-07 07:05:33

+0

讓我們嘗試'選擇Max(gpr.ProjectID)'代替。 今天我將在Visual Studio中嘗試 – 2011-04-07 13:21:41

+0

我剛剛在Visual Studio中測試之後更新了我的答案 – 2011-04-07 14:51:27