I am working on a project where I use Linq
for fetching data. Now I have a scenario where I have to check field value contains given string for that I use Contains()
function.
Everything works fine, But when any of the field is null
then it creates a problem.
personData = personData.Where(x => x.FirstName.ToLower().Contains(q.ToLower()) || x.LastName.ToLower().Contains(q.ToLower())).Select(x => x).ToList();
Here when FirstName or LastName field have a null value it throw an error.
So, how can I overcome from this problem ?