我有一个带有列表项的模型:
public class Student{
public int StudentId { get; set; }
public int ClassId { get; set; }
}
表值如下所示:
StudentId | ClassId |
---|---|
1 | 8 |
2 | 6 |
1 | 3 |
3 | 8 |
2 | 3 |
3 | 2 |
4 | 8 |
1 | 6 |
3 | 6 |
2 | 2 |
筛选器的类ID列表:
ClassId |
---|
8 |
6 |
我要 Select 位于所有筛选器类ID中的StudentID列表.
StudentId |
---|
1 |
3 |
我使用以下代码,但不起作用:
List<int> lstStudentId = Students.GroupBy(o => o.StudentId).Where(o => o.All(m => filterClassId.All(s => s == m.ClassId ))).Select(o => o.Key).ToList();