title: How to retrieve list of child tasks from a Product Backlog Item in TFS API?
body: <p>Given a certain product backlog id, I want to programmatically retrieve a list of tasks that are child to the PBI.</p>
  
  <p>I am aware that there's not one field in the task that says "Parent PBI Id". I have a version of code that is working, but that's really really slow, since I have do perform part of my filtering int the client.</p>
  
  <p>See how I'm currently doing:</p>
  
  <pre><code>string wiqlQuery =
      string.Format(
          "Select ID, [Remaining Work], State " +
          "from WorkItems " +
          "where (([Work Item Type] = 'Task')" +
          " AND ([Iteration Path] = '{0}' )" +
          " AND (State &lt;&gt; 'Removed')" +
          " AND (State &lt;&gt; 'Done')) ",
          sprint, storyId);
  
  // execute the query and retrieve a collection of workitems
  WorkItemCollection workItems = wiStore.Query(wiqlQuery);
  
  if (workItems.Count &lt;= 0)
      return null;
  
  var result = new List&lt;TaskViewModel&gt;();
  foreach (WorkItem workItem in workItems)
  {
      var relatedLink = workItem.Links[0] as RelatedLink;
      if (relatedLink == null) continue;
      if (relatedLink.RelatedWorkItemId != storyId) continue;
  
      Field remWorkField = (from field in workItem.Fields.Cast&lt;Field&gt;()
                            where field.Name == "Remaining Work"
                            select field).FirstOrDefault();
      if (remWorkField == null) continue;
      if (remWorkField.Value == null) continue;
  
      var task = new TaskViewModel
      {
          Id = workItem.Id,
          ParentPbi = relatedLink.RelatedWorkItemId,
          RemainingWork = (double) remWorkField.Value,
          State = workItem.State
      };
  
      result.Add(task);
  }
  
  return result;
  </code></pre>