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

I am learning LINQ. I want to write this query in LINQ.

Jacob H
  • 2,455
  • 1
  • 12
  • 29
Muhammad Ali
  • 1
  • 2
  • 4
  • 1
    Where is your code, what have you tried? – Neo Jun 30 '17 at 13:14
  • 2
    Please never just post SQL and ask for conversion. At least show a class model so navigation properties and the multiplicity of associations are visible. Also, tell what type of LINQ you're targeting (to entities?), and show your own first efforts. They clarify more to us than you might think. – Gert Arnold Jun 30 '17 at 13:22
  • "bitwise and" operator is the same in C# and Sql. The equivalent of NOT IN in Linq is https://stackoverflow.com/questions/183791/how-would-you-do-a-not-in-query-with-linq Give it a try and then publish your code. Also there are some automated tools for converting sql into Linq but I don't know how reliable they are https://stackoverflow.com/questions/296972/sql-to-linq-tool – derloopkat Jun 30 '17 at 13:35

1 Answers1

1

I'm told that a SQL query like this will be faster.

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

Converting that to linq, we get:

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
James Curran
  • 101,701
  • 37
  • 181
  • 258