'Entity Framework Core LINQ expression could not be translated [duplicate]

I'm fairly new to EF Core, and I am trying to filter a set of jobs based on whether the appointment date is in the past and the status.

Why would this result in an error?

var maxJobAgeDate = DateTime.Now.AddDays(-14);

JobSummaries.Where(j => DateTime.Parse(j.AppointmentDate) < maxJobAgeDate && j.JobStatus == JobStatus.CompleteSignOffConfirmed);

The error:

The LINQ expression 'DbSet .Where(j => DateTime.Parse(j.AppointmentDate) < __maxJobAgeDate_0 && (int)j.JobStatus == 4)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

I'm using EF Core.



Solution 1:[1]

You need to specify the date format while converting in the Non-standard ISO types.

Try this.

JobSummaries.Where(j => DateTime.ParseExact(j.AppointmentDate,"yyyy-MM-dd",CultureInfo.InvariantCulture) < maxJobAgeDate 
                && j.JobStatus == JobStatus.CompleteSignOffConfirmed).ToList();

I strongly recommend fixing this at a database level

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1