我的代码是这样的
List<Entity> lists = CacheManager.GetAllEntity();
List<long> firstLists = lists .Select <Entity,long>(x=>x.ID).ToList<long>();
List<Entity2> secondLists = CacheManager.GetAllEntity2();
Entity2 的样子:
public class Entity2
{
public long ID;
public long EntitytID;
}
现在假设 firstsLists 包含 {1,2,3,4}
。
第二个包含
ID EntitytID
1 1
1 2
1 3
1 4
2 1
2 4
3 1
4 2
5 4
那么我的输出应该给我
ID EntitytID
1 1
1 2
1 3
1 4
因为项目 id 1 具有所有值 {1,2,3,4}
。
最佳答案
怎么样:
var results = secondLists
.GroupBy(z => z.ID)
.Where(z => firstLists.All(z2 => z.Select(z3 => z3.EntitytID).Contains(z2)))
.SelectMany(z => z);
关于c# - 我想要第二个列表中的项目,其中包含第一个列表中的所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16142298/