Reputation: 3381
I've tried searching for this but couldn't find examples that suited my situation.
I have this method for returning customers. How can I use the string array of codes to filter it? Contains doesn't work for me.
public static List<Customer> GetCustomers(string[] customerCodesArray)
{
using (busDataContext g = new busDataContext())
{
return g.Customers.Where(
x => x.customerCode.Contains(customerCodesArray)).ToList();
}
}
Upvotes: 31
Views: 48930
Reputation: 17701
Try the following code:
return g.Customers.Where(x => customerCodesArray.Contains(x.customerCode)).ToList();
Upvotes: 43
Reputation: 1221
Try
return g.Customers.Where(x=>customerCodesArray.Contains(x.CustomerCode)).ToList();
Upvotes: 5
Reputation: 20764
I guess this is what you want
return g.Customers.Where(x => customerCodesArray.Contains(x.customerCode)).ToList();
Upvotes: 3
Reputation: 839234
I think you need to reverse the Contains
expression because you want to see if the array contains the customer code, not the other way around.
Try this:
return g.Customers.Where(x => customerCodesArray.Contains(x.customerCode)).ToList();
Upvotes: 11
Reputation: 82654
You are backwards:
return g.Customers.Where(x => customerCodesArray.Contains(x.customerCode)).ToList();
Upvotes: 21