I'm trying to dynamically build a LINQ where statement but I'm having problems trying to write a IN statement using the contains method on a list.
Here is my code:
IQueryable<Customer> customers =
(from cus in objectCustomer
select cus); \\objectCustomer is all customers
//List of customer ID's passed into the method.
string[] sCustomerIDs = (string[])DictionaryParameters["CustomerIDs"];
customers = customers.Where(c => c.Assets.Any(a => sAssetIDs.Contains(a.UN_Asset.ToString())));
return customers.Cast<T>().ToList();
When the return line is run I receive the following error: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
Any ideas? If I change IQueryable to IEnumerable to query runs but I need to use IQueryable as I'm using the Entity Framework and IEnumerable returns all the records before my filter takes place.
Many Thanks.