1

I have a query that looks something like this...

string value
            return DataContext.Tags.Where(t => t.Keys.Any(k => k.Ring.RingName == category))
                .Where(t => t.Keys.Any(k => k.Ring.Keys.Any(c => c.Tag.TagName == value)));

It works good, I love it. But it needs to do something extra. the 'value' string will actually be a string[] - is there any way to basically change the last lambda to say 'if the TagName matches anything found in this string[]'?

2
  • Why don't you combine the Where calls? Commented Jan 15, 2010 at 16:28
  • .Where(t => t.Something && t.SomethingElse) Commented Jan 15, 2010 at 16:53

2 Answers 2

3

Like this: (Untested)

string[] values
return DataContext.Tags.Where(t => t.Keys.Any(k => k.Ring.RingName == category))
                       .Where(t => t.Keys.Any(k => k.Ring.Keys.Any(c => values.Contains(c.Tag.TagName))));
Sign up to request clarification or add additional context in comments.

5 Comments

You just may be the greatest person that has ever lived. Thank you so much.
string[] does not have a Contains method. Weird, maybe it does and it just doesn't show up in intellisense.
@SLak yeah, I noticed that if I just typed it out that it compiled fine, but when searching for the method using intellisense it didn't show that was valid.
It had contains when I tried it. I'll find out if it works and get back to you.
@BarretJ: You were probably looking at a string (non-array), which has LINQ extensions that don't show up in IntelliSense. string[].Contains should appear in IntelliSense.
0

If you can't change the declaration of value c =>(new List (value)).Contains(c.Tag.TagName)

If you can, can you declare it as List?

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.