[英]Inserting ID in Textbox And Return Values Entity Framework c#
我在文本框中插入了学生ID,并且我想在不同的标签中返回所有值。 如果正在使用三张表的学生,参加和课程。 学生的SID在“参加”中是一个外键,而课程的cID在“参加者”表中是一个外键。 我要加入这三个表。
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.