title: Remove child list item when checking grandchild list using Linq
body: <p>The following code shows how I am assigning data into <code>IEnumerable&lt;UnCompletedJobDetailsBO&gt;</code>.</p>
  
  <p>There is a list (<code>IEnumerable&lt;UnCompletedJobDetailsBO&gt;</code>) that has another list (<code>List&lt;JobDetailsBO&gt;</code>), with that child list (<code>List&lt;JobDetailsBO&gt;</code>) having a list on it. But the <code>AllocationDetailList</code> only ever has one list item.</p>
  
  <pre><code>public IEnumerable&lt;UnCompletedJobDetailsBO&gt; GetControlDetails(DateTime startDate)
  {
      var controlDetails =
         (from booking in db.BookingDetail
          where booking.BookingDateTime &gt;= startDate
          orderby booking.DocketNo
          select new UnCompletedJobDetailsBO()
          {
              CustomerName = booking.Customer.Name,
              CompanyName = booking.CompanyDetail.Name,
              JobList =
                 (from job in db.BookingJob.Where(x =&gt; x.BookingID == booking.BookingID) //get job list
                  select new JobDetailsBO()
                  {
                      JobID = job.JobID,
                      JobType = job.JobType,
                      ItemName = job.ItemName,
                      AllocationDetailList =
                         (from jobAllocationDetail in db.JobAllocation
                          join returnUnCollected in db.JobReturnUnCollected
                              on jobAllocationDetail.JobAllocationDetailID
                              equals returnUnCollected.JobAllocationDetailID
                              into returnJob
  
                          from returnUnCollected in returnJob.DefaultIfEmpty()
                          where (jobAllocationDetail.Booking.BookingID == booking.BookingID)
                          select new AllocationBO()
                          {
                              JobUnCollectedID = returnJob.JobUnCollectedID,
                              JobType = jobAllocationDetail.JobType,
                              CurrentStatus = jobAllocationDetail.CurrentStatus,
                          }).DefaultIfEmpty().ToList(),
                  }).DefaultIfEmpty().ToList(),
          }).ToList();
  
      return controlDetails;
  }
  </code></pre>
  
  <p>I want to remove the <code>JobList</code> item if the inner list (<code>AllocationDetailList</code>) item satisfies the condition below. Sometimes <code>AllocationDetailList</code> may be null, so I check that also. But when I write below query, it does not remove that particular <code>JobList</code> item that satisfies the condition. Thanks in advance.</p>
  
  <pre><code>public List&lt;UnCompletedJobDetailsBO&gt; RemovePODFromSelectedList(
      List&lt;UnCompletedJobDetailsBO&gt; unCompletedJobDetailsBO)
  {
      unCompletedJobDetailsBO
          .SelectMany(y =&gt; y.JobList)
          .ToList()
          .RemoveAll(x =&gt; ((x.AllocationDetailList[0] != null) ?
              x.AllocationDetailList[0].JobType == "D" &amp;&amp;
                  x.AllocationDetailList[0].JobUnCollectedID == null &amp;&amp;
                  x.AllocationDetailList[0].CurrentStatus == 5 :
              x.AllocationDetailList.Count &gt; 1));
  
      return unCompletedJobDetailsBO;
  }
  </code></pre>