I basically want the following sql query as a lambda expression:
SELECT studentname, coursename, grade
FROM student S, course C, grade G
WHERE S.id = G.studentid AND C.coursecode = G.coursecode AND G.grade<='B';
I am having trouble as I have to join 3 tables together.
Well, that looks something like this as a query expression:
(I’d normally use a variable name of
queryinstead ofq– I’ve just usedqfor formatting purposes here.)You could translate this into explicit
Joincalls with lambda expressions, but I’d strongly advise you to use query expressions for complex queries like this.Note that I’ve changed the order of the query to allow the “where” clause to be expressed as simply and efficiently as possible. In all likelihood a SQL query planner would optimize it anyway, but for something like LINQ to Objects this would help.