首页 > 解决方案 > 在 linq 的 join 命令中获取左连接对象

问题描述

我有 2 个课程:StudentClass 和 SelectedLessonClass。

StudentClass{
 studentId,
 name,
 family}
SelectedLessonClass{
 studentId,
 lessonId}

我需要选择课程 ID=12 的学生的信息;

我使用加入命令:

students=students.join(selectedLessons.where(sl=>sl.lessonId==12).tolist(),st=>st.studentId,sl=>sl.studentId,.....)

请指导我,我必须填写什么而不是......?

谢谢

标签: c#visual-studiolinqjoinresultset

解决方案


假设你有listStudentslistLessons你可以尝试这样的事情(result是符合你标准的学生列表):

var result = from s in listStudents
             join l in listLessons
             on s.studentId equals l.studentId
             where l.lessonId=12
             select s;

推荐阅读