2

表1:学生

StudentID, StudentName

表2:コース

CourseID, CourseName

表3:グループ

GroupID, GroupName

表4:StudentCourseGroup

StudentID, CourseID, GroupID

「xyz」コースに所属するすべての学生が次の形式で欲しい

Class MyStudent

    string StudentName
    String [] Groups

StudentName各学生は1つ以上のグループのメンバーになることができ、各オブジェクトのグループのリストを保持するように、LINQクエリに「ClassMyClass」を入力する必要があります。

そうすることができるLINQクエリを提案していただけますか。

4

1 に答える 1

1
var query = from s in db.Student
            join scg in db.StudentCourseGroup on s.StudentID equals scg.StudentID
            join c in db.Course on scg.CourseID equals c.CourseID
            join g in db.Group on scg.GroupID equals g.GroupID
            where c.CourseName == "xyz"
            select new { s, g } into x
            group x by x.s into studentGroups
            select new MyStudent {
                StudentName = studentGroups.Key.StudentName,
                Groups = studentGroups.Select(sg => sg.g.GroupName)
            };
于 2013-01-04T11:17:28.640 に答える