【发布时间】:2019-10-04 05:16:40
【问题描述】:
我的应用中有两个组合框。其中一个cmb1 与一个名为Branches 的表绑定,另一个cmb2 与另一个名为teachers 的表绑定。在名为subjectteachers 的表中,它们之间的关系是多对多的。我需要知道如何获取所选cmb1 的 ID
并使用该 ID 在表 subjectteachers 中搜索并从表 teachers 中获取名称以将其放入 cmb2
CollegeContext cd = new CollegeContext();
Branch SectionCB = CBTypeOfSection.SelectedItem as Branch;
var query = from b in cd.Branches
where (from st in cd.SubjectTeachers
where (st.IdBranch == SectionCB.Id &&
(from t in cd.Teachers
where
(t.Id == st.IdTeacher)
select t.Name) select st))
select b;
TeachersComboBox.ItemsSource = query.ToList();
【问题讨论】:
-
var query = cd.Subjectteachers.Where(x=>x.IdBranch==SectionCB.Id).Select(x=>x.Teacher);
-
它有效.....非常感谢.....我可以再问一个吗?
-
如果我想在教师表中获取一些数据,例如:idwork ==5 在同一个组合框中的教师表中
-
TeachersComboBox.DisplayMemberPath = "idwork";
-
我会把它放在答案中,所以你可以接受它