【问题标题】:Inserting ID in Textbox And Return Values Entity Framework c#在文本框中插入 ID 并返回值实体框架 c#
【发布时间】:2015-05-12 22:21:42
【问题描述】:

我在文本框中插入学生的 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

通过加入这三个表格,我想显示哪个学生上过哪门课程以及该课程的名称是什么

【问题讨论】:

    标签: c# linq entity-framework


    【解决方案1】:

    通过一次又一次的尝试,我找到了如何使用 foreach 循环加入和获取不同类的字段的答案

            foreach (var eb in dbContext.Attends) {
    
                metroLabel3.Text= eb.Student.First_Name.ToString();
    
            }
    

    【讨论】:

      猜你喜欢
      • 2021-05-17
      • 2016-07-05
      • 2019-12-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-02
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      相关资源
      最近更新 更多