开发者

LINQ, use string[] in a query

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

string value
            return Da开发者_C百科taContext.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[]'?


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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜