使用Linq从包含的列表中的列表中进行选择

使用Linq从包含的列表中的列表中进行选择,linq,select,lambda,any,Linq,Select,Lambda,Any,我的语法有问题 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(); 公共班级学生 {

我的语法有问题

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();
公共班级学生
{
国际学生;
字符串名;
}
公共课
{
int CourseId;
列出学生名单;
}
int[]studentId={5,7,12};
List allCourses=myDataContext.Courses.ToList();
使用Lambda表达式或查询表达式,如何获得包含数组
studentId
中任何学生的所有课程的筛选列表

var result = from course in allCourses
             where course.Students.Any(x => studentIds.Contains(x.StudentId))
             select course;