I am trying to implement a query in LINQ that uses a left outer join with multiple conditions in an ON clause.
I will use the example of the following two tables Project (ProjectID, ProjectName) and Task (TaskID, ProjectID, TaskName, Completed). I want to see a complete list of all projects with their respective tasks, but only those tasks that have been completed.
I cannot use the filter for Completed == true , because it will filter out any projects that do not have completed tasks. Instead, I want to add Completed == true to the ON clause of the connection so that a complete list of projects is displayed, but only completed tasks will be shown. Projects without completed tasks will show one line with a zero value for the task.
Here is the basis of the request.
from t1 in Projects join t2 in Tasks on new { t1.ProjectID} equals new { t2.ProjectID } into j1 from j2 in j1.DefaultIfEmpty() select new { t1.ProjectName, t2.TaskName }
How to add && t2.Completed == true to the on clause?
I can not find any LINQ documentation on how to do this.
join linq
Kuyenda Oct 05 '11 at 16:40 2011-10-05 16:40
source share