我有两个表学生和老师,我想比较他们的学校分支,只显示匹配的学生使用linq下拉
以下是代码,
var teacher = db.TeacherEnroll.Select(x =>new{x.BranchClassesId,x.SubjectId});
var student = db.EnrollInClass.Select(x => new { x.ClassSubject.ClassesId, x.BranchClassesId });
ViewBag.show = db.EnrollInClass.ToList().Where(x=>student.Equals(teacher));
return View();
答案 0 :(得分:1)
下面的查询应该给那些与老师有共同分支的学生
var students =
(from t in db.TeacherEnroll
from s in db.EnrollInClass.Where(s => s.BranchClassedId == t.BranchClassesId)
select s).ToList();