使用LINQ连接多个表

时间:2015-01-29 20:19:58

标签: c# .net linq

我正在尝试将此查询转换为LINQ查询:

select proj.CustomerName, proj.projectid, ProjectNumber, oe.FullName, oe.Rate, oe.jobid, opj.BillRate, hours.Hours, hours.WeekStart 
    from RMT_TaskEmployeeHours hours

        join OracleEmployees oe
        on hours.EmployeeNumber = oe.EmployeeNumber

            join OracleProjectTasks tasks
            on hours.TaskId = tasks.TaskID

                join OracleProjects proj
                on tasks.ProjectID = proj.ProjectID

                    left join OracleProjectJobs opj
                    on opj.ProjectID = proj.ProjectID
                    and oe.jobid = opj.JobID
                    where oe.Office  like '%san francisco%'
                    and opj.EndDate is null
                    and WeekStart > '2015-1-22' and WeekStart < '2015-2-19'

写完后我卡住了:

var test = db.RMT_TaskEmployeeHours.
                   Join(
                       db.OracleEmployees,
                       hours => hours.EmployeeNumber,
                       oe => oe.EmployeeNumber,
                       (hours, oe) => new {hours, oe}).
                   Join(
                        db.OracleProjectTasks,
                        oh => oh.oe.
                   ).

1 个答案:

答案 0 :(得分:0)

为什么不试试http://www.sqltolinq.com/

尝试在Linqer上查找教程。这将帮助您开始将SQL写入LINQ。