tags:

views:

34

answers:

2

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 lamda to say 'if the TagName matches anything found in this string[]'?

+3  A: 

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))));
SLaks
You just may be the greatest person that has ever lived. Thank you so much.
Stacey
string[] does not have a Contains method. Weird, maybe it does and it just doesn't show up in intellisense.
BarrettJ
@BarretJ: LINQ adds one.
SLaks
@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.
BarrettJ
It had contains when I tried it. I'll find out if it works and get back to you.
Stacey
Yes! It works beautifully.
Stacey
@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.
SLaks
A: 

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?

BarrettJ