I have a List of Entity Framework DAL objects where I am using a query parameter string that can include commas. I am trying to get all objects from the DAL List that satisfy the values in the query parameter string.
I have the following Linq statement that yields what I am expecting:
dalList = dalList
.Where(aa => queryParamString.Split(',')
.Any((x => (aa.GetType().GetProperty(kvp.Key).GetValue(aa, null)).ToString().ToLower() == x.ToLower())))
.ToList();
The above statement works fine if the list does not contain a null value for the reflected property.
How can I include a null check into this Linq statement to avoid the NullReferenceException on the first ToString() method call?
Edit: kvp.Key is a string representation to a database column
Aucun commentaire:
Enregistrer un commentaire