I have the following class:
public class Employee
{
public string Name {get; set;}
...
}
and a LINQ query in EF Core 2.1
Employee GetEmployeeByName(string name) {
return Context.Employee.Where ( w =>String.Compare(w.Name, name, true) == 0).FirstOrDefault();
}
After it is converted to Net Core EF 3.1, there is an error.
LINQ expression 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()
, orToListAsync()
I have to change the query to
Employee GetEmployeeByName(string name) {
return Context.Employee.Where ( w =>w.Name.ToLower() == name.ToLower()).FirstOrDefault();
}
Is there a better way to do this?
.Where(x => x.Name == "Smith")
the case sens comes from the db, and SQLS isn't normally case sens by default – Aixenprovence