Question

I'm having syntax troubles.

public class Student
{
   int StudentId;
   string Name;
}

public class Course
{
   int CourseId;
   List<Student> Students;
}


int[] studentIds = { 5, 7, 12 };
List<Course> allCourses = myDataContext.Courses.ToList();

Using Lambda expressions or query expressions, how do I get a filtered list of all the Courses containing any of the Students in the array studentIds?

Était-ce utile?

La solution

var result = from course in allCourses
             where course.Students.Any(x => studentIds.Contains(x.StudentId))
             select course;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top