I’m having an issue toLower() in lambda query. I have this code
var filterResult = articleList
.Where(m => m.Summary
.Contains(filteredModel.Keyword) || m.Body.Contains(filteredModel.Keyword) || m.Headline.Contains(filteredModel.Keyword)
|| m.Title.Contains(filteredModel.Keyword))
.AsQueryable();
I need to add toLower() method as sql. For example:
var filterResult = articleList
.Where(m => m.Summary.toLower()
.Contains(filteredModel.Keyword.toLower()) || m.Body.toLower().Contains(filteredModel.Keyword.toLower()) || m.Headline.toLower().Contains(filteredModel.Keyword.toLower())
|| m.Title.toLower().Contains(filteredModel.Keyword.toLower()))
.AsQueryable();
As above code, lambda doesn’t allow to use. I wonder if there is other way to do to achieve this.
ToLowershould work, try breaking it up into different lines to narrow down which check is failing – remember it won’t execute until you actually pull the results down e.g.Also just an FYI – if your converting to lower case for culture-independant comparison then you should be using ToLowerInvariant…or better yet using ToUpperInvariant as it’s more reliable.