user3163213
user3163213

Reputation: 701

compare strings with multiple strings

I am trying to select from multiple string matches.

Condition-

select from CardTagTables whose column CardTagName doesn't have these strings- String1, String2.

List<string> stringArray =new List<string>{ "String1", "String2" };
var query = (from u in db.CardTables
             join v in db.CardTagTables
             on u.CardID equals v.FKCardTagID
             where u.IsApproved == "YES" &&
                   !v.CardTagName.Contains(stringArray.ToString())

I am trying to fetch only records except strings in stringArray.

There are two strings- String1 and String2

Upvotes: 1

Views: 98

Answers (3)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101681

You just need to change Contains order, instead of this:

!v.CardTagName.Contains(stringArray.ToString())

Try:

!stringArray.Contains(v.CardTagName)

Upvotes: 1

Oscar Bralo
Oscar Bralo

Reputation: 1907

Try somethign like this:

var result = CardTagTables.Select(x => stringArray.Any(y => x.CardTagName.Contains(y))).ToList();

It´s untested, but I think that is the idea ;)

Upvotes: 0

nvoigt
nvoigt

Reputation: 77304

Replace

v.CardTagName.Contains(stringArray.ToString()

with

v.CardTagName.Any(element => stringArray.Contains(element))

Upvotes: 1

Related Questions