You have parenthesis around those OR
'd expressions in LINQ. You'll need to make sure they're in your SQL as AND
has a higher precedence than OR
(i.e. AND
is evaluated first):
declare @currentDate = GETDATE()
AND (Start is null
OR @currentDate => Start)
AND (End is null
OR @currentDate <= End)
AND End > Start
Edit: Also you've written Start is not null
rather than Start is null
(same for End
).
You're also comparing two dates in your LINQ for your Start date, but you're comparing a date-time with a date in your SQL. If you want to replicate this then you'll need to convert/offset your Start
to make the SQL consistent: