2013-02-19 84 views
0

喜有人可以幫助我如何寫在LINQ下面的查詢,因爲我是新來的LINQ提前子查詢幫助

select * from Employee where employeeid = 'E101' 
or empdept = (select dept from departments where deptid = 'D101') 

感謝

+0

你能告訴我們你試過什麼嗎? – 2013-02-19 04:33:24

+0

from e in employee where(e.employeeid =='E101')) || e.empdept ==(來自部門的d,其中d.deptid =='D101')) – jestges 2013-02-19 08:58:46

回答

0

您可以使用組加入

from e in employee 
join d in deparment.Where(x => x.deptid == "D101") 
    on e.empdept equals d.dept into g 
where e.employeeid == "E101" || g.Any() 
select e; 

產生以下SQL

DECLARE @p0 NVarChar(1000) = 'E101' 
DECLARE @p1 NVarChar(1000) = 'D101' 

SELECT * 
FROM [employee] AS [t0] 
WHERE ([t0].[employeeid] = @p0) OR (EXISTS(
    SELECT NULL AS [EMPTY] 
    FROM [deparment] AS [t1] 
    WHERE ([t0].[empdept] = [t1].[dept]) AND ([t1].[deptid] = @p1) 
    ))