我是LINQ的新手,所以我很擔心一些查詢,我相信這很簡單。無論如何,我一直在嘲笑我的頭,但我很難過。幫助將T-SQL查詢轉換爲LINQ查詢
任何人都可以幫助我將這個T-SQL查詢轉換成LINQ查詢嗎?有一次,我看到它是怎麼做的,我相信我可以重新考慮語法一些問題:
SELECT BlogTitle
FROM Blogs b
JOIN BlogComments bc ON
b.BlogID = bc.BlogID
WHERE b.Deleted = 0
AND b.Draft = 0
AND b.[Default] = 0
AND bc.Deleted = 0
GROUP BY BlogTitle
ORDER BY MAX([bc].[Timestamp]) DESC
只是爲了證明我有試圖解決這個我自己,這裏是我」已經拿出到目前爲止,雖然它不編譯,更不用說工作...
var iqueryable =
from blog in db.Blogs
join blogComment in db.BlogComments on
blog.BlogID equals blogComment.BlogID
where blog.Deleted == false
&& blog.Draft == false
&& blog.Default == false
&& blogComment.Deleted == false
group blogComment by blog.BlogID into blogGroup
orderby blogGroup.Max(blogComment => blogComment.Timestamp)
select blogGroup;
謝謝大衛。正如你所建議的,我選擇通過向Blog部分類添加一個BlogComments屬性來解決這個問題。 – campbelt 2010-06-02 00:09:14