I have the following query:
SELECT FROM tblMailToSend
WHERE (DateToSend < @dateToSend OR DateToSend IS NULL) AND DateSent IS NULL
@dateToSend is passed in as a param
I'm trying to convert this to linq to sql query.
I've got:
db.MailToSend.Where(m => m.DateToSend == null || m.DateToSend <= dateToSend)
.Where(m => m.DateSent == null)
But this is giving the following SQL:
SELECT *
FROM [dbo].[tblMailToSend] AS [t0]
WHERE ([t0].[DateSent] IS NULL) AND (([t0].[DateToSend] IS NULL) OR ([t0].[DateToSend] <= @p0))
Which is giving the wrong results...
What Linq query would I need to match the correct (first) sql?