I am new to lambda expressions and I am having issues trying to figure out how to represent my entity framework query in one. I also could be wrong and there is just a better way to do what I want. If this is true please let me know. My scenario is I have an advanced search screen where you could choose to search bu name, customer number, or phone number. You can search by more than 1 if you want. I am using Entity Framework as my backend and have repositories set up for my tables. Below is the code I am trying to use
Func<Parties, bool> exp;
exp = null;
if (vm.CustomerNumberCriteria != null)
{
custID = Convert.ToInt32(vm.CustomerNumberCriteria);
exp = o => o.ID == custID;
}
if (vm.NameCriteria != null)
exp += o => o.LastName.Contains(vm.NameCriteria) || o.FirstName.Contains(vm.NameCriteria) || o.MiddleName.Contains(vm.NameCriteria) || o.Designation.Contains(vm.NameCriteria);
if (vm.PhoneNumberCriteria != null)
exp += o => o.CentralPhoneNumbers.Any(child => child.PhoneNumber == vm.PhoneNumberCriteria);
//TODO set tempresults
tempresults = custs.All.Where(exp).ToList();
My issue is it seems to treat this like an and and I need results if there is a match on any of the search criteria.
Thanks