Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我一直在尝试为此使用 lambda:
var y = from r in rs.Returns from z in r.Tags where z.Name.Contains(c) select r;
我试过var r = rs.Returns.Where(x=>x.Tags.Where(x=>x.Name.Contains(c)));了,但没有用。什么是正确的 lambda,所以我不必使用y&z
var r = rs.Returns.Where(x=>x.Tags.Where(x=>x.Name.Contains(c)));
y
z
您需要SelectMany翻译第二个“from”子句:
SelectMany
var y = rs.Returns .SelectMany(r => r.Tags, (r, z) => new { r, z }) .Where(pair => pair.z.Name.Contains(c)) .Select(pair => pair.r);
这是一个非常直接的翻译。另一种选择是使用:
var y = rs.Returns.Where(r => r.Tags.Any(z => z.Name.Contains(c)));