日期:2014-05-20  浏览次数:20881 次

这两句SQL怎么写成LINQ?
SQL1:
select 
a.ProgramListID,a.OrderIndex,a.ProgramID,b.ProgramName,b.ProgramLength  
from (select * from dbo.T_R_ProgramList_Program where ProgramListID=1) a
left join
 T_Program b
on a.ProgramID=b.ProgramID
order by a.OrderIndex asc

SQL2:
select 
a.ProgramListID,a.ProgramID,a.OrderIndex,b.ProgramName,b.ProgramLength
from dbo.T_R_ProgramList_Program a,
dbo.T_Program b
where a.ProgramListID=1 and a.ProgramID=b.ProgramID
order by a.OrderIndex asc

这两个SQL用LINQ怎么写啊?

------解决方案--------------------
linq 使用 join
var q = 
from e in db.Employees 
join o in db.Books on e.EmployeeID equals o.EmployeeID into b 
from x in b.DefaultIfEmpty() 
where 条件
select new 

e.ID, 
e.Name, 
o.BookName 
}; 

------解决方案--------------------
LINQ :
var re = (from b in T_Program 
join a in T_R_ProgramList_Program
on t.ProgramID equals p.ProgramID
where a. ProgramListID == 1
&& a.ProgramID==b.ProgramID
select new {
b.ProgramListID,
b.OrderIndex,
a.ProgramName,
a.ProgramLength }).orderBy(f=>f.OrderIndex )