1

I am trying to write linq lambda exp and IDK how to convert this from sql

SELECT * FROM Students s
WHERE s.MathGrades > 5 
AND s.FizGrades > 5 
AND NOT (s.MathGrades =2 AND s.FizGrades = 2) 

How to write "AND NOT" in linq Lambda exp ?

Coko
  • 37
  • 4
  • 1
    Can you give an example that *makes logical sense*? Both `MathGrades` and `FizGrades` are known to be greater than 5. You don't need to additionally check that they're not both equal to 2. – Damien_The_Unbeliever Oct 13 '22 at 06:13
  • There's no `AND NOT` operator. `NOT` is applied to an expression and that result is combined with another using `AND`. The equivalent of `NOT` in C# is `!`. The equivalent of `AND` is `&&`, so `exp1 AND NOT exp2` is equivalent to `exp1 && !exp2` – Panagiotis Kanavos Oct 13 '22 at 06:20

1 Answers1

1

The same way you would write it in C# code generally. AND NOT is && !

The full LINQ query:

from s in students
where s.MathGrades > 5 && s.FizGrades > 5 && !(s.MathGrades == 2 && s.FizGrades == 2)
select s
Simon Biber
  • 497
  • 4
  • 5
  • OMG, feel so stupid, I tried it like this but I Wrote it 's.MathGrades = 2' instead of 's.MathGrades == 2' :/ Thanks – Coko Oct 13 '22 at 06:25