var q = dc.tblHelpCentreQuestions.Where(c => c.userID == UserID);
q.OrderByDescending(c => c.dateSubmitted);
This works fine, but I also need to return the count of records returned from tblHelpCentreReplies where QuestionID equals tblHelpCentreQuestions.ID. This is easy enough for me in SQL, can someone show me how this is done in LINQ to SQL?
Edit
I’ve got as far as this:
var q =
from question in dc.tblHelpCentreQuestions
join replies in dc.tblHelpCentreReplies on question.ID
equals replies.ticketID
where question.userID == UserID
orderby question.dateSubmitted descending
select new { question, replies.Count() };
But replies.Count() throws:
Invalid anonymous type member
declarator. Anonymous type members
must be declared with a member
assignment, simple name or member
access.
the linq query would look like this:
update
if you have a relation mapping than that could be a bit easier