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.
}
问题:
我有两个分别名为standard
和student
的表。我想通过外键关系检索所有学生信息。我到处搜索这个主题,但没有找到任何合适的解决方案。请帮我解决这个问题。
答案 0 :(得分:0)
如果您已配置关系,请尝试使用include语句(假设标准是父级和1:1,否则翻转和/或添加集合):
var balance = (from StandardX std in db.Standards.Include("Student")
select new { std.Student.StudentID, std.Student.StudentName, std.StandardName });