1

I've been trying to use a lambda for this :

var y = from r in rs.Returns from z in r.Tags where z.Name.Contains(c) select r;

I tried var r = rs.Returns.Where(x=>x.Tags.Where(x=>x.Name.Contains(c)));but it didnt work. What is the correct lambda so I dont have to use y & z

1 Answer 1

7

You need a SelectMany to translate the second "from" clause:

var y = rs.Returns
          .SelectMany(r => r.Tags, (r, z) => new { r, z })
          .Where(pair => pair.z.Name.Contains(c))
          .Select(pair => pair.r);

That's a pretty direct translation. Another alternative would be to use:

var y = rs.Returns.Where(r => r.Tags.Any(z => z.Name.Contains(c)));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.