SQL to LINQ
-
Hi . How can I change this SQL query to LINQ :
SELECT SUM(Grades.Grade * Lessons.LesTotalUnit) / SUM(Lessons.LesTotalUnit) AS avg FROM Grades INNER JOIN Lessons ON Grades.LesCode = Lessons.LesCode WHERE (Grades.StNo = @stno) AND (Grades.EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_1 WHERE (StNo = @stno))) AND (Grades.Semester IN (SELECT MAX(Semester) AS Expr1 FROM Grades AS Grades_2 WHERE (StNo = @stno) AND (EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_3 WHERE (StNo = @stno)))))
-
Hi . How can I change this SQL query to LINQ :
SELECT SUM(Grades.Grade * Lessons.LesTotalUnit) / SUM(Lessons.LesTotalUnit) AS avg FROM Grades INNER JOIN Lessons ON Grades.LesCode = Lessons.LesCode WHERE (Grades.StNo = @stno) AND (Grades.EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_1 WHERE (StNo = @stno))) AND (Grades.Semester IN (SELECT MAX(Semester) AS Expr1 FROM Grades AS Grades_2 WHERE (StNo = @stno) AND (EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_3 WHERE (StNo = @stno)))))
Can you format your code? it's harder than necessary to read it as you posted it. If you want to learn LINQ I recommend 101 LINQ Samples[^] as well as getting and using LINQPad[^] which is a pretty good tool for learning LINQ and try code snippets. For learning how to convert SQL to LINQ, this resource[^] is quite useful (it's in VB but it should be pretty easy to do the translation to C#). If you can't invest the time to learn right now (although I highly recommend it) you can use Linqer[^]
If you think you can do a thing or think you can't do a thing, you're right - Henry Ford Emmanuel Medina Lopez
-
Hi . How can I change this SQL query to LINQ :
SELECT SUM(Grades.Grade * Lessons.LesTotalUnit) / SUM(Lessons.LesTotalUnit) AS avg FROM Grades INNER JOIN Lessons ON Grades.LesCode = Lessons.LesCode WHERE (Grades.StNo = @stno) AND (Grades.EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_1 WHERE (StNo = @stno))) AND (Grades.Semester IN (SELECT MAX(Semester) AS Expr1 FROM Grades AS Grades_2 WHERE (StNo = @stno) AND (EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_3 WHERE (StNo = @stno)))))
http://techgurulab.com/course/sql-tutorial/[^] This link is help to basic concept on SQL