I have a model with list items:
public class Student{
public int StudentId { get; set; }
public int ClassId { get; set; }
}
The table values are similar to the following:
StudentId | ClassId |
---|---|
1 | 8 |
2 | 6 |
1 | 3 |
3 | 8 |
2 | 3 |
3 | 2 |
4 | 8 |
1 | 6 |
3 | 6 |
2 | 2 |
classId list for filter:
ClassId |
---|
8 |
6 |
I want to select the list of StudentId where are in all filter classId.
StudentId |
---|
1 |
3 |
I use this code but not working:
List<int> lstStudentId = Students.GroupBy(o => o.StudentId).Where(o => o.All(m => filterClassId.All(s => s == m.ClassId ))).Select(o => o.Key).ToList();