I’m using LINQ to SQL.
I have a Projects table. I also have a Tasks table. A Task can have a project.
I would like a query that can return a list of Projects that do not have any tasks.
Here is how I find all tasks for a project:
public static IEnumerable<Task> GetAllByProject(int? projectID)
{
KezberPMDBDataContext db = new KezberPMDBDataContext();
return from p in db.Tasks
where p.ProjectID == projectID
select p;
}
Now I need to find all projects where the above query returns nothing.
Assuming the FK relationship exists between Project and Task and it’s one to many.
Else, let’s find the project ids from all tasks and then find the projects that are outside those ids.