-1

数据库

任何人都可以帮助我将以下 SQL 查询转换为 LinqToSql 语法。它涉及我的表中的多个表。我不确定我是否使用了正确的查询类型。任何帮助将不胜感激。

public IQueryable<tblCourseNeededHours>(int departmentId, string semester)
{
    return from = 
        "SELECT tblCourseNeededHours.Semester, tblCourseNeededHours.NeededHoursPerWeek, 
                tblCourseNeededHours.AssignToInstituteAdministrator, 
                tblCourseNeededHours.Freezed, tblCourse.CourseName, 
                tblInstitute.InstituteName, tblDepartment.DepartmentName
         FROM tblCourseNeededHours 
             INNER JOIN tblCourse ON 
                 tblCourseNeededHours.CourseID = tblCourse.CourseID 
             INNER JOIN tblInstitute ON 
                 tblCourse.InstituteID = tblInstitute.InstituteID 
             INNER JOIN tblDepartment ON 
                 tblInstitute.DepartmentID = tblDepartment.DepartmentID";
}
4

1 回答 1

2

Well, if you have proper foreign keys in your database you can just do

Var x = from nh in db.tblCourseNeededHours
        select nh.Semester, nh.xxxx, nh.tblCourse.CourseName, 
        nh.tbCourse.tblInstitute.CourseName

and so forth.

No need to do any of the inner joins yourself. That is the beauty of Linq2Sql.

于 2012-04-10T20:38:26.550 回答