I have a List<string> of variable count, and I want to query (via LINQ) a table to find any items that contain any of those strings in the Text column.
Tried this (doesn’t work):
items = from dbt in database.Items where (stringList.FindAll(s => dbt.Text.Contains(s)).Count > 0) select dbt;
Query would be something like:
select * from items where text like '%string1%' or text like '%string2%'
Is this possible?
Check this article out to do what you want:
http://www.albahari.com/nutshell/predicatebuilder.aspx
This works like a dream. I essentially cut and pasted their code and got this back (with my own data-scheme of course):
Here is the code I ran for the proof of concept:
I’d suggest going to the site for the code and explanation.
(I am leaving the first answer because it works well if you need an IN statement)