Reputation: 701
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
Reputation: 101681
You just need to change Contains
order, instead of this:
!v.CardTagName.Contains(stringArray.ToString())
Try:
!stringArray.Contains(v.CardTagName)
Upvotes: 1
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
Reputation: 77304
Replace
v.CardTagName.Contains(stringArray.ToString()
with
v.CardTagName.Any(element => stringArray.Contains(element))
Upvotes: 1