public void QueryById() { // Get an existing query and associated ID for proof of concept. // Get the root query folders var queries = WitClient.GetQueriesAsync(TeamProject.Name, null, 1).Result; var myQueriesFolder = queries.Where(q => !q.IsPublic.Value).FirstOrDefault(); if (myQueriesFolder != null && myQueriesFolder.IsFolder.GetValueOrDefault(false) && myQueriesFolder.HasChildren.GetValueOrDefault(false)) { var firstQuery = myQueriesFolder.Children.First(); // Query by ID and process results var queryResults = WitClient.QueryByIdAsync(firstQuery.Id).Result; Console.WriteLine($"Query with name: '{firstQuery.Name}' and id: '{firstQuery.Id}' returned {queryResults.WorkItems.Count()} results:"); if (queryResults.WorkItems.Count() > 0) { // GetWorkItemsAsync can only return 200 items at a time, so only take the first 200 of the work items list. // Larger lists will require batching calls to GetWorkItemsAsync until the list is processed. var workItemList = queryResults.WorkItems.Select(wi => wi.Id).Take(200); string[] fields = new string[] { "System.Id", "System.Title" }; var workItems = WitClient.GetWorkItemsAsync(workItemList, fields).Result; foreach (WorkItem wi in workItems) { Console.WriteLine($"WorkItem Id: '{wi.Id}' Title: '{wi.Fields["System.Title"]}'"); } } else { Console.WriteLine($"Query with name: '{firstQuery.Name}' and id: '{firstQuery.Id}' did not return any results."); Console.WriteLine($"Try assigning work items to yourself or following work items and run the sample again."); } Console.WriteLine(); } else { Console.WriteLine("My Queries haven't been populated yet. Open up the Queries page in the browser to populate these, and then run the sample again."); } }