how can i write this in LINQ :
SELECT
T.TestId,
S.SubjectName+' >> '+T.TestName +' ('+ CONVERT(VARCHAR(10),COUNT(Q.TestId)) +')' TestData
FROM
Test T LEFT OUTER JOIN Subject S
ON T.SubjectId = S.SubjectId
LEFT OUTER JOIN Quest Q
ON T.TestId = Q.TestId
GROUP BY
Q.TestId,
T.TestId,
T.TestName,
S.SubjectName
ORDER BY
COUNT(Q.TestId) DESC
Need help in writing Left Outer Join & Group by in LINQ .
Case II :
SELECT
S.SubjectName,
T.TestName,
Q.Question,
A.Answer,
A.IsCorrect
FROM Ans A
INNER JOIN Quest Q
ON A.QuestId = Q.QuestId
AND A.QuestId IN ( SELECT
Q.QuestId
FROM Quest Q
INNER JOIN Test T
ON Q.TestId = T.TestId )
INNER JOIN Subject S
ON A.SubjectId = S.SubjectId
INNER JOIN Test T
ON A.TestId = T.TestId
Thanks.
To perform an outer join in Linq, you need to use the
DefaultIfEmptyextension method:Note that you don’t need both
t.TestIdandq.TestIdin thegroup byclause, since they will have the same value. For the last part, I’m usingAsEnumerableso that the final projection is performed in memory rather than in the DB, which enables the use ofstring.Format.