LINQ queries: Retrieve the list using any

advertisements

I have two tables. Contact table and a client table. ContactID is a foreign key in client table. I have a query that returns a List of contacts. I want a seperate list of all the clients where client.contactid in the first list of contacts. I think i can use Any method just now sure how. Thanks. Using LINQ to EF

 List<Contact> contacts = GetContactByCompany().ToList();

Have something along the lines of

List<Client> = from client in Client.Any(client => contacts.ID.Contains(client.ContactID))


Looks like you are seeking for something like this

var clients = Client.Where(client => contacts.Any(contact => contact.ID == client.ContactID)).ToList();

or

var contactIds = contacts.Select(contact => contact.ID).ToList();
var clients = Client.Where(client => contactIds.Contains(client.ContactID)).ToList();