You will need to create a simple class that takes the personal information of the registered students.
1 2 3 4 5 6 7 8 9 10 11 | public class Student { public int StudentID { get; set; } public string Name { get; set; } public string EmailAddress { get; set; } public string Department { get; set; } public Datetime DOB { get; set; } public string Gender { get ; set; } } |
The next step is to fill some dummy data and create a list of students that belongs to Computer Science department.
1 2 3 4 5 6 7 8 9 10 | public List GetStudents() { List Students = new List(); Students.Add(new Student { ID = 1, Name = "Student 1", EmailAddress = "Name1@abc.com" , Department = "ComputerScience " , DOB = "YYYY-MM-DD " , Gender = "Option A " }); Students.Add(new Student { ID = 2, Name = " Student 2", EmailAddress = "Name2@abc.com " , Department = "ComputerScience " , DOB = "YYYY-MM-DD " , Gender = "Option A " }); Students.Add(new Student { ID = 3, Name = " Student 3", EmailAddress = "Name3@abc.com " , Department = "ComputerScience " , DOB = "YYYY-MM-DD " , Gender = "Option B " }); Students.Add(new Student { ID = 4, Name = " Student 4", EmailAddress = "Name4@abc.com " , Department = "ComputerScience " , DOB = "YYYY-MM-DD " , Gender = "Option B" }); return Students; } |
This is the reverse scenario of the above query. If you want to select the students who are not from Computer Science department then you can use the following query:
1 2 3 4 5 6 | // Get the exam results of those students who are not in the Computer Science department var result = _examRepository.GetResults () .Where(p => GetStudents().All(p2 => p2.StudentID != p.StudentID)) .ToList(); |