I'm trying to use Array.Contains on a string array within a Linq query:
var otherMatchingDevices = from d in selectedDevices
from c in mldb.Companies
where d.CompanyID == c.CompanyID && c.Deleted == 0
where searchTerms.Contains(d.Name.ToString(), StringComparer.CurrentCultureIgnoreCase) || searchTerms.Contains(c.CompanyName.ToString(), StringComparer.CurrentCultureIgnoreCase)
select d;
When the query is evaluated it crashes with "Unsupported overload used for query operator 'Contains'.
I tested this code using the StringComparer and it works fine and prints out "fOO":
string[] sList = { "fOO", "bar" };
string[] array = { "foo" };
List<string> stringlist = sList.ToList();
var qry = from s in stringlist
where array.Contains(s, StringComparer.CurrentCultureIgnoreCase)
select s;
if (qry.Count() > 0) Console.WriteLine(qry.First().ToString());
Can anyone show me how to use a case insensitive Array.Contains within a Linq query? I do NOT want to convert the original string ToUpper() or ToLower() as it is expensive and it changes the original data.