2010-06-02 42 views
0

我有SQL查詢:如何SQL查詢轉換爲LINQ到SQL

SELECT News.NewsId, News.Subject, Cm.Cnt FROM dbo.News 
LEFT JOIN 
(SELECT Comments.OwnerId, COUNT(Comments.OwnerId) as Cnt 
FROM Comments 
WHERE Comments.CommentType = 'News' 
Group By Comments.OwnerId) Cm 
ON Cm.OwnerId = News.NewsId 

但我想LINQ到SQL查詢,我怎麼能將此轉換爲LINQ?

+1

你有什麼這麼遠嗎? – bkaid 2010-06-02 20:36:51

回答

2

你可能會發現下載LinqPad,這將使它非常容易編寫LINQ和測試。它也將幫助你學習語法。真棒工具。它是免費的。

+0

謝謝。這是一個很棒的工具 – name1ess0ne 2010-06-05 19:58:41

1

如何,我可以將它轉換爲LINQ?

實踐! :)

from news in News 
let count = news.Comments 
    .Where(comment => comment.CommentType == "News") 
    .Count() 
select new {news.NewsId, news.Subject, Count = count};