1

我遇到语法问题。

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

4

1 回答 1

5
var result = from course in allCourses
             where course.Students.Any(x => studentIds.Contains(x.StudentId))
             select course;
于 2012-01-12T22:09:29.843 回答