-2
select * from EmployeeScheduleRoles esr 
inner join
(
    select esr.ScheduleID from Schedules sch 
    inner join EmployeeScheduleRoles esr on esr.ScheduleID = sch.ID 
    inner join Employees emp on emp.ID = esr.EmployeeID
    where emp.ID = 15921
) subqry on subqry.ScheduleID = esr.ScheduleID 

限制:不允许“包含()”。

4

2 回答 2

1

此 LINQ 查询等同于您的 SQL 查询(对我来说似乎不是很优化)

from esr in db.EmployeeScheduleRoles
join subqry in
  (from sch in db.Schedules
   join esr2 in db.EmployeeScheduleRoles on sch.ID equals esr2.ScheduleID
   join emp in db.Employees on esr2.EmployeeID equals emp.ID
   where emp.ID == 15921
   select esr2.ScheduleID)
on esr.ScheduleID equals subqry
select esr
于 2013-06-27T20:10:53.193 回答
0
var yours = (from esr in EmployeeScheduleRoles
join sch in Schedules on esr.ScheduleID equals sch.ID 
join emp in Employees  on emp.ID equals esr.EmployeeID
where emp.ID == 15921
select esr).toList()

顺便说一句,您的 sql 子查询是多余的,您可以 select esr.* from Schedules sch

于 2013-06-27T19:54:08.383 回答