Supposse, I have a class:
public class PersonalInfo
{
public string Firsname {get;set;}
public string Lastname {get;set;}
public string Email {get;set;}
public string Phone {get;set;}
}
The data come from file.
And, I need to select data from file by this property:
private IList<PersonalInfo> FindByPersonalData(string firstName, string lastName, string email, string phone)
{
...
}
Several properties can be empty, but if they filled then search by them. I can check every combination, but it’s ugly. What is the best solution?
Thanks
A typical sub-query would be to use a short-circuit on each field. Making some assumptions about your data structures, that could look something like this:
Or, depending on your Linq preference:
So, if any parameter is null/empty, the comparison with the data will be skipped.