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.
如何根据嵌入文档中的值选择文档?例如,我有一个 r 类,它有一个 i 类的列表。我想选择所有具有 i.name=="foo" 的 r。
如果你想选择所有r至少有一个i的,i.Name == "foo"可以使用这个查询:
r
i
i.Name == "foo"
var result = collectionOfRs.Where(r => r.ListOfIs.Any(i => i.Name == "foo"));
如果你想选择所有r有all i的i.Name == "foo"你可以使用这个:
var result = collectionOfRs.Where(r => r.ListOfIs.All(i => i.Name == "foo"));