views:

68

answers:

1

I was expecting the following LINQ query to retrieve all contacts with the specified phone number but instead it returns all contacts that don't have a phone number at all.

var query = from contact in dc.Contacts
            where contact.Phones.All(phone => phone.PhoneNumber == "5558675309")
            select contact;

What am I doing wrong here?

+2  A: 

I should have been using the Any extension method, not All.

The following code works just fine:

var query = from contact in dc.Contacts            
            where contact.Phones.Any(p => p.PhoneNumber == "5558675309")            
            select contact;
joshb