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(); } }
What are LINQ Operators? The LINQ Operators are nothing but a set of extension methods that are used to write LINQ Query. These LINQ extension methods provide lots of very useful features which we can apply to the data source. Some of the features are filtering the data, sorting the data, grouping the data, etc.
An IEnumerable<T>.
The standard query operators provide query capabilities including filtering, projection, aggregation, sorting and more. There are two sets of LINQ standard query operators: one that operates on objects of type IEnumerable<T>, another that operates on objects of type IQueryable<T>.
Try the following code:
return g.Customers.Where(x => customerCodesArray.Contains(x.customerCode)).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With