2012-01-12 7 views
1

構文の問題があります。 ラムダを使用してLinqを使用して、リストが含まれているリストから選択する

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(); 

クエリ式を表現、どのように私は、アレイstudentIdsの学生のいずれかを含む全てのコースのフィルタリングされたリストを得るのですか?

答えて

5
var result = from course in allCourses 
      where course.Students.Any(x => studentIds.Contains(x.StudentId)) 
      select course; 
関連する問題