Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ to SQL - select where text like string array

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?

like image 651
9 revs Avatar asked Feb 04 '09 17:02

9 revs


1 Answers

kind of new to the whole LINQ to SQL game, but does this syntax help?

string[] items = new string[] { "a", "b", "c", "d" };

var items = from i in db.Items
             where items.Contains(p.text)
            select i;

Got it from:

http://blog.wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql/

like image 165
Matthew Doyle Avatar answered Nov 11 '22 22:11

Matthew Doyle