Help Converting T-SQL Query to LINQ Query
Posted
by campbelt
on Stack Overflow
See other posts from Stack Overflow
or by campbelt
Published on 2010-05-31T23:20:53Z
Indexed on
2010/05/31
23:23 UTC
Read the original article
Hit count: 562
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;
© Stack Overflow or respective owner