Left Outer Join using Entity Framework and Lambda Expressions

c# entity-framework lambda linq-to-entities

Question

Employee
id, name, datejoin, deptID

and another table that is

Marketing 
id, name, deptID

What I am trying to do is search of deptID from Employee table in Marketing to see if it exists, if it doesn't exists want to add name and deptID from Employee table into Marketing table. Basically I believe it is left outer join.

I am trying to do is using lambda expressions and EF I am new to this area so was wondering how to accomplish that. I have created the entities fine need to figure out the lambda expression

tTlEntities sde = new tTlEntities();
sde.t_Marketing.Where(x=>x.deptID == t_Employee.deptID).

That is how far I went I know some outer joining is needed. Help Pleasee

1
4
5/23/2013 6:24:34 AM

Popular Answer

It could be done with a left outer join of employee to marketing and a check for null marketing results for the employee, or you can use not exists which in LINQ to Entities is:

tTlEntities sde = new tTlEntities();
var employeeQuery = sde.t_Employee.Where(
                     e=> !sde.t_Marketing.Any(m => m.deptID == e.deptID));
7
5/23/2013 11:43:39 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow