Pankaj Mishra
Pankaj Mishra

Reputation: 20358

Linq to sql between List and Comma separated string

I Have one list and one comma separated column value.

lst.Add("Beauty");
lst.Add("Services");
lst.Add("Others");

And Column value is like

Beauty,Services
Service,Others
Beauty,Others
Other,Services
Other
Beauty, Food
Food

Now I Want all those rows which contains any list item.

Output result is

Beauty,Services
Service,Others
Beauty,Others
Other,Services
Other
Beauty, Food

First Edit

These comma separated values are one of my table's one column value. I need to check against that column.

Upvotes: 0

Views: 1536

Answers (2)

Yahia
Yahia

Reputation: 70369

try

List<string> lst = ....; // your list of strings

string[] somecolumnvalues = new string[] { "", "",... }; // your columvalues

var Result = from l in lst from c in somecolumnsvalues where c.Contains (l) select c;

Upvotes: 0

msarchet
msarchet

Reputation: 15242

Assuming you can figure out how to get the RowCollection

RowCollection.Where(row => row.Split(",").ToList().Where(x => list.Contains(x)).Any()).ToList();

will evaluate to true if the row contains a value from the list.

Upvotes: 2

Related Questions