我的应用程序中有两个组合框。其中一个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();
答案 0 :(得分:0)
这叫做lambda,它对您很有帮助,希望您喜欢它。
var query = cd.Subjectteachers.Where(x=>x.IdBranch==SectionCB.Id).Select(x=>x.Teacher);
TeachersComboBox.DisplayMemberPath = "idwork";