C# 在文本框中插入ID并返回值实体框架c
我正在文本框中插入学生ID,我想返回不同标签中的所有值。如果我使用三张桌子,学生,参加和课程。学生的SID在Attent中为外键,课程的cID在Attent表中为外键。 我正在加入这三张桌子C# 在文本框中插入ID并返回值实体框架c,c#,linq,entity-framework,C#,Linq,Entity Framework,我正在文本框中插入学生ID,我想返回不同标签中的所有值。如果我使用三张桌子,学生,参加和课程。学生的SID在Attent中为外键,课程的cID在Attent表中为外键。 我正在加入这三张桌子 Attend obJ = new Attend(); Student oAd = new Student(); oAd.sID = int.Parse(metroTextBox1.Text); var entryPoint = (from ep in dbContext.Atten
Attend obJ = new Attend();
Student oAd = new Student();
oAd.sID = int.Parse(metroTextBox1.Text);
var entryPoint = (from ep in dbContext.Attends
join en in dbContext.Students on ep.sID equals en.sID join te
in dbContext.Courses on ep.cID equals te.cId
where en.sID == oAd.sID
select new{
Name = en.First_Name,
Course = te.Name,
Presents=ep.Present,
Absents=ep.Absent,
});
foreach (var iL in entryPoint) {
metroLabel1.Text = iL.Name;
metroLabel2.Text = iL.Course;
metroLabel3.Text = iL.Absents.ToString();
metroLabel4.Text = iL.Presents.ToString();
}
代码没有给出我想要显示的任何类型的响应,尽管它没有给出任何类型的错误
Student table Sid is in Attend Table
Course table cID is in Attend Table
通过连接这三个表,我想显示哪个学生参加了哪门课程,该课程的名称是什么通过反复尝试,我找到了如何使用foreach循环连接和获取不同类字段的答案
foreach (var eb in dbContext.Attends) {
metroLabel3.Text= eb.Student.First_Name.ToString();
}