title: LINQ query to get data from a table connected by three tables away
body: <p>I have three tables.</p>
  <ol>
  <li>organisationalUnit</li>
  <li>user</li>
  <li>Tasks</li>
  </ol>
  <p>I want to return back data from the tasks table where the authorized user is in a particular department and the user too is in this department.
  For example, Sally is in the HR department. She wants to view Jim's tasks. Jim is also in the HR department with sally, therefore she is allowed to view his tasks. However, she should not be able to view John's tasks as he is in the sales department.</p>
  <pre><code>organisationalUnit
  --------------------
  ID     |     name
  --------------------
  1      |     HR
  2      |     Sales
  
  
  
  
        Users
  ----------------------------------------
  ID     |     name     |  OUID(FK)
  ----------------------------------------
  4      |     Jim      |  1
  5      |     Sally    |  1
  6      |     John     |  2
  
  
  
        Tasks
  ----------------------------------------------
  ID     |     TaskInfo           |  userID(FK)
  -----------------------------------------------
  1      |     Task for Jim       |     4
  2      |     Task for john      |     5
  3      |     Task for Sally     |     6
  </code></pre>
  <p>current LINQ code</p>
  <pre><code>public async Task&lt;IEnumerable&lt;TaskSchedule&gt;&gt; GetTasks(string RoleName)
  {         
       // return back ou ID
       var OUObjReturned = _context.OrganisationalUnits.Where(o =&gt; o.Name == RoleName).ToList();
       var OUID = OUObjReturned[0].Id;
  
       // get users based on the OUID       
       var userObjects = _context.Users.Where(u =&gt; u.OUId == OUID).ToList();
  
       // returns back with an array of users that have the Organisational unit ID   
       var userIDFromObject = userObjects[0].Id;
  
       //need further code to query the task table to return back tasks based on userID
  
  
  }
  </code></pre>
  <p>I am now stuck on what to do after I get back the list of users with their ids. Is there a better way to code up the LINQ query than the one I have done above?</p>
  <p>The LING query should be able to return back a list of tasks based on the organisationalUnit ID being sent into the query first.
  In the case above, sending the organisationalUnit ID of 1, should return back task row 1 and 2 as jim and sally are in OUID 1.</p>