如何比较两个表数据并仅在下拉列表

时间:2018-03-12 05:29:17

标签: asp.net linq model-view-controller

我有两个表学生和老师,我想比较他们的学校分支,只显示匹配的学生使用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(); 

1 个答案:

答案 0 :(得分:1)

下面的查询应该给那些与老师有共同分支的学生

var students = 
(from t in db.TeacherEnroll
from s in db.EnrollInClass.Where(s => s.BranchClassedId == t.BranchClassesId)
select s).ToList();