title: How do I Get the Children of a DevOps Work Item?
body: <p>I'm trying to piece together a C# console app that accesses the work items in TFS/DevOps via it's API and compares the original estimate field parent work item with that of all its children and then spits out the name and ID of any work items that do not add up.</p>
  <p>So far, I have been able to get back a list of all my work items with the original estimates included, but I still need to get the children of each work item so that I can loop through them and compare the summation of their original estimates with that of their parent. Given how little I know about C# and queries I am pretty stuck right now.</p>
  <p>Since linked items are not reportable fields, I have to use $expand to execute a query to get the info I need (at least that's what the doc linked below says). This is where I am stuck. Any tips?</p>
  <p><a href="https://docs.microsoft.com/en-us/azure/devops/report/extend-analytics/work-item-links?view=azure-devops" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/devops/report/extend-analytics/work-item-links?view=azure-devops</a></p>
  <p>Here is what I have so far.</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  
  using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
  using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
  using Microsoft.VisualStudio.Services.Common;
  
  namespace QueryWorkitems0619
  {
      class Program
      {
          static void Main(string[] args)
          {
              string orgName = &quot;{Organization's name}&quot;;
              string PAT = &quot;{Personal Access Token}&quot;;
  
              Uri uri = new Uri($&quot;https://dev.azure.com/{orgName}&quot;);
              string project = &quot;Wingnit_2&quot;;
              VssBasicCredential credentials = new VssBasicCredential(&quot;&quot;, PAT);
              //create a wiql object and build our query
              Wiql wiql = new Wiql()
              {
                  Query = &quot;Select * &quot; +
                  &quot;From WorkItems &quot; +
                  &quot;Where [System.TeamProject] = '&quot; + project + &quot;' &quot; +
                  &quot;And [System.State] &lt;&gt; 'Closed' &quot; +
                  &quot;And [System.RelatedLinkCount] &gt; '0'&quot; +
                  &quot;Order By [State] Asc, [Changed Date] Desc&quot;
              };
              //create instance of work item tracking http client
              using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
              {
                  //execute the query to get the list of work items in the results
                  WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
                  //some error handling
                  if (workItemQueryResult.WorkItems.Count() != 0)
                  {
                      //need to get the list of our work item ids and put them into an array
                      List&lt;int&gt; list = new List&lt;int&gt;();
                     
                      foreach (var item in workItemQueryResult.WorkItems)
                      {
                          list.Add(item.Id);
                      }
                      int[] arr = list.ToArray();
                      //build a list of the fields we want to see
                      string[] fields = new string[5];
                      fields[0] = &quot;System.Id&quot;;
                      fields[1] = &quot;System.Title&quot;;
                      fields[2] = &quot;System.RelatedLinkCount&quot;;
                      fields[3] = &quot;System.Description&quot;;
                      fields[4] = &quot;Microsoft.VSTS.Scheduling.OriginalEstimate&quot;;
                      //get work items for the ids found in query
                      var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result;
                      //loop though work items and write to console
                      foreach (var workItem in workItems)
                      {
                          foreach (var field in workItem.Fields)
                          {
                              Console.WriteLine(&quot;- {0}: {1}&quot;, field.Key, field.Value);
                          }
                      }
  
                      Console.ReadLine();
                  }
              }
          }
      }
  }
  </code></pre>