I need to create a function that receives a list of strings, and returns a list of all the items that match (i.e., SQL "LIKE", case-insensitive and ignoring diacritics):
// Pseudocode example
IEnumerable<Item> Search(List<String> patterns)
{
var result = new List<Item>();
foreach (var Item in context.Items)
{
bool matches = true;
foreach (var pattern in patterns)
{
if (!Item.Name.Contains(pattern))
{
matches = false;
break;
}
}
if (matches)
{
result.Add(Item);
}
}
return result;
}
While something similar to this works, it's less than ideal (it seems horribly inefficient).
Is it possible to create a (possibly LINQ) query that generates something similar to the following SQL?:
SELECT *
FROM items
WHERE items.name LIKE :pattern1
AND items.name LIKE :pattern2
...
AND items.name LIKE :patternN