public void QueryById() { // Querying by ID doesn't really exist in the WIT model like it does in REST. // In this case, we are looking up the query definition by its ID and then creating a new Query with its corresponding wiql // Get an existing query and associated ID for proof of concept. If we already have a query guid, we can skip this block. QueryHierarchy queryHierarchy = TeamProject.QueryHierarchy; var queryFolder = queryHierarchy as QueryFolder; QueryItem queryItem = queryFolder?.Where(f => f.IsPersonal).FirstOrDefault(); QueryFolder myQueriesFolder = queryItem as QueryFolder; if (myQueriesFolder != null && myQueriesFolder.Count > 0) { var queryId = myQueriesFolder.First().Id; // Replace this value with your query id // Get the query definition var queryDefinitionById = WIStore.GetQueryDefinition(queryId); var context = new Dictionary <string, string>() { { "project", TeamProject.Name } }; // Obtain query results using the query definition's QueryText Query obj = new Query(this.WIStore, queryDefinitionById.QueryText, context); WorkItemCollection queryResults = obj.RunQuery(); Console.WriteLine($"Query with name: '{queryDefinitionById.Name}' and id: '{queryDefinitionById.Id}' returned {queryResults.Count} results:"); if (queryResults.Count > 0) { foreach (WorkItem result in queryResults) { Console.WriteLine($"WorkItem Id: '{result.Id}' Title: '{result.Title}'"); } } else { Console.WriteLine($"Query with name: '{queryDefinitionById.Name}' and id: '{queryDefinitionById.Id}' did not return any results."); Console.WriteLine($"Try assigning work items to yourself or following work items and run the sample again."); } } 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."); } Console.WriteLine(); }