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)
)
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)
)
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
};
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