0

I have Sql query:

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

But I want linq-to-sql query, how I can convert this to linq?

1
  • 1
    What do you have so far? Commented Jun 2, 2010 at 20:36

2 Answers 2

2

You might find it helpful to download LinqPad, which will make it extremely easy to write LINQ and test it. It will also help you learn the syntax. Awesome tool. And it's free.

Sign up to request clarification or add additional context in comments.

Comments

1

how I can convert this to linq?

Practice! :)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.