I'm using ef to query to databse my query is to get a date from database (string type), convert it to date type and compare it to another date
var res = _context.Course.Where(a => DateTime.ParseExact(a.CourseStart, "MM/dd/yyyy", CultureInfo.InvariantCulture) > fromDate).ToList();
and the result is always InvalidOperationException: The LINQ expression 'DbSet() .Where(c => DateTime.ParseExact( s: c.CourseStart, format: "MM/dd/yyyy", provider: __InvariantCulture_0) > __fromDate_1)' could not be translated.
CodePudding user response:
InvalidOperationException: The LINQ expression 'DbSet() .Where(c => DateTime.ParseExact( s: c.CourseStart, format: "MM/dd/yyyy", provider: __InvariantCulture_0) > __fromDate_1)' could not be translated.
The reason is that implicit client evaluation has been disabled from EF Core 3.
You can switch to client evaluation explicitly by inserting a call to AsEnumerable
like below:
var res = _context.Course.AsEnumerable() //add here...
.Where(a => DateTime.ParseExact(a.CourseStart, "MM/dd/yyyy", CultureInfo.InvariantCulture) > fromDate)
.ToList();