Question

The following query doesn't give me the expected result. What I am expecting is I need all contacts if any of the conditions are matched, but it doesn't give me that result

 Func<BAL.Contact, bool> expr_contact =
            x => x.Name.NullSafeStartWith(txtSearch.Text)
          || x.ContactDetails.All(a => a.TP.StartsWith(txtSearch.Text));

I searched for contact name, but if the searchtext does not match the contact details, then I get an empty result :(

Was it helpful?

Solution

You're saying "Name starts with X.. OR ALL Contact Details start with X". You want "Name starts with X .. Or ANY Contact Details start with X":

Func<BAL.Contact, bool> expr_contact =
        x => x.Name.NullSafeStartWith(txtSearch.Text)
      || x.ContactDetails.Any(a => a.TP.StartsWith(txtSearch.Text));
//                        ^^^ Any
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top