I an trying to build a simple search LINQ statement. As the strings are passed into the WHERE, the empty strings are causing false results.
tmp = (from p in tmp
where
p.Customer.custEmail.Contains(filter.Email) &&
p.Customer.custLastName.Contains(filter.LastName) &&
p.orderID == id
select p).ToList();
}
If the filter.LastName is empty, the query still tries to find the “”, which results in NO RECORDS.
Without writing a bunch of
if (!String.IsNullOrWhiteSpace(filter.LastName))
for each Filter item, is there a way to do this within the LINQ command?
Just add the check to the where clause: