0

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 :(

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3030035
  • 143
  • 1
  • 8

1 Answers1

4

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
Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138