0

I have a trouble like this guy: stackoverflow link

I can get only WorkItemReference with Wiql help.

var query = new Wiql
                {
                 Query = string.Format("SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State]" +
                                      " FROM WorkItems" +
                                     $" WHERE [System.Id] IN ({ids})" +
                                      " ORDER BY [System.Id]")
                };
WorkItemQueryResult queryResult = await witHttpClient.QueryByWiqlAsync(query);

if (queryResult.WorkItems.Any())
{
    foreach (WorkItemReference child in queryResult.WorkItems)
    {
         //do something
    }
}

I am forced each time to ask the TFS by id for get WorkItem and this is very long time

imsome1
  • 1,182
  • 4
  • 22
  • 37

3 Answers3

2

Thank you for your answer, but i found this way.

I just use WorkItemTrackingHttpClient.GetWorkItemsAsync(ids, expand: WorkItemExpand.Relations) method and get all children WorkItems. It is fast enough for my.

1

Change your query string to this:

Select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] From WorkItemLinks where (Source.[System.TeamProject] = 'TeamProject' and [System.Id] IN ({ids})) and ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') and (Target.[System.TeamProject] = 'TeamProject' and Target.[System.WorkItemType] <> '') order by [System.Id] mode (MustContain)
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
0

You are using work item query language (WIQL) to dynamically create a query in your code. Running a query is a two step process.

  1. Find the query id for a given project and query path (example: Shared Queries/Current Iteration/Open User Stories).
  2. Use the query id from step 1 and execute it to get the results. These results only contain a limited reference back to the work items.
  3. Use the query result to get the expanded the work items

It's not able to get the TFS work items and his children WorkItems(not WorkItemReference) in one trip from TFS. The linked workitems will not expanded automatically in parent work item. Fore more details please refer below tutorials:

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62