LINQ的SQL查询如何在linq中编写查询

时间:2017-06-30 13:11:12

标签: sql linq

select * 
from impact 
where (usedin&1)=1 
and impactid not in 
    (select impactid 
    from responsetime 
    where scontractid= scontractid  )

我正在学习LINQ。 我想在LINQ中编写此查询。

1 个答案:

答案 0 :(得分:1)

我告诉我这样的SQL查询会更快。

select * 
from impact i
left outer join responsetime r on i.impactid = r.impactid 
where (usedin&1)=1  
  and scontractid= scontractid 
  and r.impact is null

将其转换为linq,我们得到:

from i in impact
from r in responsetime.Where(rr=>i.impactid = rr.impactid).DefaultIfEmpty()
where (i.usedin&1)=1  
  and i.scontractid= scontractid 
  and r.impact is null
select i