1

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

3 Answers 3

1

Replace

v.CardTagName.Contains(stringArray.ToString()

with

v.CardTagName.Any(element => stringArray.Contains(element))
Sign up to request clarification or add additional context in comments.

3 Comments

It says me List<string>.Contains(string) has some invalid arguments.
What type is CardTagName?
Wow, I thought CardTagName would again be a list of tags. If that is only a sigle string and you want those that are not contained in your array, why didn't you do it that way: !stringArray.Contains(v.CardTagName)
1

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

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

Try:

!stringArray.Contains(v.CardTagName)

Comments

0

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 ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.