Help Converting T-SQL Query to LINQ Query
- by campbelt
I am new to LINQ, and so am struggle over some queries that I'm sure are pretty simple. In any case, I have been hiting my head against this for a while, but I'm stumped.
Can anyone here help me convert this T-SQL query into a LINQ query? Once I see how it is done, I'm sure I'll have some question about the syntax:
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
Just to show that I have tried to solve this on my own, here is what I've come up with so far, though it doesn't compile, let alone work ...
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;