0

こんにちは、私はLINQが初めてなので、誰かがLINQで以下のクエリを書く方法を手伝ってくれますか

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

前もって感謝します

4

1 に答える 1

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)
    ))
于 2013-02-19T14:15:12.540 に答える