Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WIQL工作项中获得层次结构_C#_Tfs_Azure Devops_Tfs Workitem_Wiql - Fatal编程技术网

C# 如何在WIQL工作项中获得层次结构

C# 如何在WIQL工作项中获得层次结构,c#,tfs,azure-devops,tfs-workitem,wiql,C#,Tfs,Azure Devops,Tfs Workitem,Wiql,我在TFS中有这样的等级结构 其中,1功能可以有“N”个产品待办事项,单个产品待办事项可以有“N”个任务/错误 树形结构 功能1-> PB1-> 任务1、任务2、任务3 我的问题 string querystring = string.Format("select [System.Id], [System.Title],[Story.Author],[Story.Owner],[System.AssignedTo]," + " [System.WorkItemTy

我在TFS中有这样的等级结构 其中,1功能可以有“N”个产品待办事项,单个产品待办事项可以有“N”个任务/错误 树形结构

功能1-> PB1-> 任务1、任务2、任务3

我的问题

string querystring = string.Format("select [System.Id], [System.Title],[Story.Author],[Story.Owner],[System.AssignedTo]," +
                " [System.WorkItemType],[Microsoft.VSTS.Scheduling.StoryPoints],[Microsoft.VSTS.Common.Priority]," +
                "[Microsoft.VSTS.Scheduling.Effort], [Actual.Effort.Completed]" +
                ",[System.State]," +
                "[System.IterationPath]" +
                " FROM WorkItemLinks" +
                " WHERE" +
                " ([Source].[System.TeamProject]='{0}'" +
                " and [Source].[System.IterationPath] UNDER 'MRI_SCRUM_GIT\\Pluse Pheonix\\Sprint 1'" +
                " and [Source].[System.WorkitemType]<>'' " +
                ")" +

                " and ([System.Links.LinkType]='System.LinkTypes.Hierarchy-Forward')" +
                " and ([Target].[System.WorkItemType] <> '' )" +
                " ORDER BY [System.Id] " +
               " mode (Recursive)", projectname);
现在我如何获得C代码中的所有字段,如下图所示
以下网站上已有一段代码片段:


如何通过c编码知道ID是否有父ID?假设我有结构F->P>T,其中F可以有很多P,P可以有很多T,那么如何知道一个特定的T是否有F?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi.Patch.Json;
using Microsoft.VisualStudio.Services.WebApi.Patch;
using Microsoft.VisualStudio.Services.WebApi;
using System.Net.Http.Headers;
using System.Net.Http;
using Newtonsoft.Json;

public class ExecuteQuery
{
    readonly string _uri;
    readonly string _personalAccessToken;
    readonly string _project;

    /// <summary>
    /// Constructor. Manually set values to match your account.
    /// </summary>
    public ExecuteQuery()
    {
        _uri = "https://accountname.visualstudio.com";
        _personalAccessToken = "personal access token";
        _project = "project name";
    }

    /// <summary>
    /// Execute a WIQL query to return a list of bugs using the .NET client library
    /// </summary>
    /// <returns>List of Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem</returns>
    public List<WorkItem> RunGetBugsQueryUsingClientLib()
    {
        Uri uri = new Uri(_uri);
        string personalAccessToken = _personalAccessToken;
        string project = _project;

        VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);

        //create a wiql object and build our query
        Wiql wiql = new Wiql()
        {
            Query = "Select [State], [Title] " +
                    "From WorkItems " +
                    "Where [Work Item Type] = 'Bug' " +
                    "And [System.TeamProject] = '" + project + "' " +
                    "And [System.State] <> 'Closed' " +
                    "Order By [State] Asc, [Changed Date] Desc"
        };

        //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<int> list = new List<int>();
                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[3];
                fields[0] = "System.Id";
                fields[1] = "System.Title";
                fields[2] = "System.State";

                //get work items for the ids found in query
                var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result;

                Console.WriteLine("Query Results: {0} items found", workItems.Count);

                //loop though work items and write to console
                foreach (var workItem in workItems)
                {
                    Console.WriteLine("{0}          {1}                     {2}", workItem.Id, workItem.Fields["System.Title"], workItem.Fields["System.State"]);
                }

                return workItems;
            }

            return null;
        }
    }
}