Linq to Entities: Left join to get elements not found in the join
I have two unrelated (not FK defined) tables. The first table contains some tasks for which the user may not have access. I need to find all these tasks - in this case the joined table will contain zeros. How do I get them?
Here's the setting:
TimeData table
- userID
- taskID
- hours
ApprovedTasks table (the one that should contain nulls)
- taskID
- userID
The SQL query will look like this:
select * from TimeData td
left join ApprovedTasks at
on at.taskID = td.taskID and at.userID = td.userID
where at.taskID is null
Any way to pull this off with a LINQ to Entity query?
TIA
0
a source to share
1 answer
Check out ... Disjoint Union in LINQ
This should work ...
var approvedTaks = from at in ApprovedTasks.Except(
from at2 in ApprovedTasks
where at2.userID == userId and at2.taskID==taskId
select at2)
where at.userID == userId and at.taskID==taskId
select at;
but sorry, there is no database convenient to check it.
+3
a source to share