我遇到语法问题。
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();
使用 Lambda表达式或查询表达式,如何获取包含数组studentIds
中任何学生的所有课程的筛选列表?< / p>
答案 0 :(得分:5)
var result = from course in allCourses
where course.Students.Any(x => studentIds.Contains(x.StudentId))
select course;