how to use LINQ and EntityFramework to create a join

asp.net c# entity-framework linq

Question

I am trying to create a linq 2 sql in EF 4.0 query like following sql query.

SELECT * FROM Role
LEFT JOIN Queue 
ON Role.RoleId = Queue.RoleId 
WHERE QueueId = 361

So how could i do this in EF 4.0?

1
2
4/9/2012 5:08:36 PM

Accepted Answer

Normally this is done using navigation properties which are loaded when you get the entity, however you can also do this with the following:

from r in Roles
from q in Queues
where r.RoleId == q.RoleId
where q.QueueId == 361
select new { r.RoleId, q.QueueId /*other bits you want*/}
4
4/9/2012 6:28:34 AM

Popular Answer

try the following i hope it helps

i would recommend searching more about joins

var result=(from p in Roles
join pa in Queue on p.RoleId equals pa.RoleId into temproles
from addresses in temproles.DefaultIfEmpty() where temproles.queueId = 361
select new { p, pa} );


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