【问题标题】:get left joined objects in join command in linq在 linq 的 join 命令中获取左连接对象
【发布时间】:2021-05-15 06:13:08
【问题描述】:

我有 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,.....)

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

谢谢

【问题讨论】:

  • 澄清在这种情况下什么是“左连接”。您希望从查询中看到哪些示例输入和输出?
  • 什么是students,什么是selectedLessons,什么是join,where,tolist,实际的类是什么样的?请将工作代码发布为minimal reproducible example。

标签: c# visual-studio linq join resultset


【解决方案1】:

假设您有listStudents 和listLessons,您可以尝试这样的操作(result 是符合您条件的学生列表):

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

【讨论】:

  • 在主题中,OP 谈到了左连接,你是对的,但在细节中,OP 明确写了只让学生选择一些课程 ID
  • 谢谢,加入命令与 IENumerable 一起工作,但我有列表。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-19
  • 1970-01-01
相关资源
最近更新 更多