views:

94

answers:

2

The below is my SQL query and want to be in LINQ. Can anybody help for this?

SELECT EmpId,Team,_Year FROM Plan
where EmpId in
(
    select EmpId from master where 2150 in (immediatesupervisor,manager)
)
A: 

I suggest you to use join operation like this

YourDbEntities db = new YourDbEntities();

var query = from c in db.Plan
            join d in db.master on c.EmpId equals d.EmpId
            where d.ImmediateSupervisor == 2150 || d.Manager == 2150

            select new{
              c.EmpId,
              c.Team,
              c._Year
            };
Haekal
All numerical identifiers are not allowed in c#. I think '2150' is a literal value rather than a member. I'm assuming _immediatesupervisor_ and _manager_ are table members...
KristoferA - Huagati.com
thank you... I almost left about that 2150. I've correct my answer.
Haekal
A: 

Try:

var q =
from p in dc.Plan
where (
  from m in dc.Master
  where m.ImmediateSupervisor == 2150
     || m.Manager == 2150
  select m.EmpId
  ).Contains(p.EmpId)
select new { p.EmpId, p.Team, p._Year };

A great resource for commonly used linq syntax is Damien Guard's Linq-to-SQL 'cheat sheet'. It is a one-pager where you can quickly look up things like this. See http://damieng.com/blog/2009/08/12/linq-to-sql-cheat-sheet

KristoferA - Huagati.com