0

I'm a bit stuck on this. Basically I want to do something like the following SQL query in LINQ to SQL:

select Image from dbo.Employee where ID in(Select ID from dbo.Department where IsActive=1)

Any help would be gratefully received.

Thanks.

Sivakumar Piratheeban
  • 493
  • 4
  • 11
  • 39
  • 1
    possible duplicate of [how to do subquery in LINQ](http://stackoverflow.com/questions/418609/how-to-do-subquery-in-linq) – Iswanto San Jul 15 '14 at 05:09

2 Answers2

1

You can force the point with a subquery as in the question @IswantoSan links to (how to do subquery in LINQ) but, without knowing more about your entity relationships, why wouldn't simply use a join here?

from e in Employees
join d in Departments on e.ID equals d.ID
where d.IsActive
select e.Image
Community
  • 1
  • 1
lc.
  • 113,939
  • 20
  • 158
  • 187
0
select Image from dbo.Employee
.Where(u =>
dbo.Employee
.Where(x => u.IsActive = 1)
.Select(x.ID)
)

Is the query that will work for you.

Arijit Mukherjee
  • 3,817
  • 2
  • 31
  • 51