1

I am struggling to get documents expiring in less than 90 days:

var query = from doc in context.Documents
    where doc.ExpirationDate <= DateOnly.FromDateTime(DateTime.Today.AddDays(90))
    select { doc };

I know can achieve it with something like this context.Documents.Where(...), but this is just a part of a complex LINQ query, and the whole issue comes down to comparing the ExpirationDate (a DateOnly) with the current date plus 90 days

3
  • 1
    What exactly does not work for you? Do you have a compilation error? Runtime error? Results do not match what is expected? Can you please also share the "more complex query"? Commented Jan 27 at 12:15
  • What's the problem? What you posted is a very simple query that works perfectly fine as long as the table column type is date. In EF Core the LINQ queries get translated to SQL. What you posted compares the ExpirationDate column with a parameter value generated on the client, eg where ExpirationDate<= $1. The only weird thing is select { doc } - why not just return doc ? Commented Jan 27 at 12:15
  • Yes, you are right, I found the solution while I was typing my question here on SOF, my code looked different. Thanks. Commented Jan 27 at 12:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.