Entity framework 如何返回与另一个表中的外键连接的表有关的所有信息(通过IQueryable)? public IQueryable GetStudents() { var余额=(来自标准x,单位为db.Standards 在db.Students中加入StudentX 在StandardX上,StandardId等于StudentX.StandardRefId 选择新的{StudentX.StudentID,StudentX.StudentName,StandardX.StandardName}); 还余额;//我处理不了。我怎么还?请帮忙。 }

Entity framework 如何返回与另一个表中的外键连接的表有关的所有信息(通过IQueryable)? public IQueryable GetStudents() { var余额=(来自标准x,单位为db.Standards 在db.Students中加入StudentX 在StandardX上,StandardId等于StudentX.StandardRefId 选择新的{StudentX.StudentID,StudentX.StudentName,StandardX.StandardName}); 还余额;//我处理不了。我怎么还?请帮忙。 },entity-framework,web-services,asp.net-web-api,ef-code-first,asp.net-web-api2,Entity Framework,Web Services,Asp.net Web Api,Ef Code First,Asp.net Web Api2,问题: 我有两个表,分别命名为standard和student。我想通过外键关系检索所有学生信息。关于这个话题,我到处找,但没有找到合适的解决办法。请帮助我解决此问题。如果配置了关系,请尝试include语句(假设标准为父项和1:1,否则翻转和/或添加集合): 谢谢你的支持,我的朋友解决了我的问题,很简单:我应该写public IQueryable GetStudents()而不是public IQueryable GetStudents()。 public IQueryable<Stud

问题:


我有两个表,分别命名为
standard
student
。我想通过外键关系检索所有学生信息。关于这个话题,我到处找,但没有找到合适的解决办法。请帮助我解决此问题。

如果配置了关系,请尝试include语句(假设标准为父项和1:1,否则翻转和/或添加集合):


谢谢你的支持,我的朋友解决了我的问题,很简单:我应该写public IQueryable GetStudents()而不是public IQueryable GetStudents()。
public IQueryable<Student> GetStudents()
{
    var balance = (from StandardX in db.Standards
                   join StudentX in db.Students
                   on StandardX.StandardId equals StudentX.StandardRefId
                   select new { StudentX.StudentID, StudentX.StudentName, StandardX.StandardName });

    return balance; // I can't handle that. how can I return? Please help.
}
   var balance = (from StandardX std in db.Standards.Include("Student")
                  select new { std.Student.StudentID, std.Student.StudentName, std.StandardName });