如何在WIQL TFS中知道ID是否具有父ID?

时间:2018-02-20 10:22:15

标签: c# tfs azure-devops wiql

我有一个id,我想知道是否有parentid或者没有通过C#编码的TFS。在我的TFS主板中,有许多用户故事不包含Feature

我在TFS中的层次结构如下:

Feature
--->User Stories(u1,u2,u3)
--->Tasks (t1,t2,t3)

有时,用户素材不包含Feature

1 个答案:

答案 0 :(得分:3)

您可以通过直接工作项查询获得此功能。您可以在VS中创建它并保存到本地驱动器: enter image description here

然后您可以在保存的查询中找到查询文本:

<?xml version="1.0" encoding="utf-8"?><WorkItemQuery Version="1"><TeamFoundationServer>http://myserverandcollection</TeamFoundationServer><TeamProject>MyProject</TeamProject><Wiql>
SELECT [System.Id], [System.Links.LinkType], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM WorkItemLinks WHERE ([Source].[System.Id] = 174) And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Reverse') And ([Target].[System.WorkItemType] = 'Feature') ORDER BY [System.Id] mode(MustContain)
</Wiql></WorkItemQuery>

然后你可以用Microsoft.TeamFoundationServer.ExtendedClient nugate包创建应用程序

using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QueryLinkedWIQL
{
    class Program
    {
        static void Main(string[] args)
        {
            WorkItemStore _wistore = new WorkItemStore("http://myserver/myCollection");

            int _id = 175;
            string _wiql = String.Format("SELECT [System.Id] FROM WorkItemLinks WHERE ([Source].[System.Id] = {0}) And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Reverse') And ([Target].[System.WorkItemType] = 'Feature') ORDER BY [System.Id] mode(MustContain)", _id);

            Query _query = new Query(_wistore, _wiql);

            WorkItemLinkInfo[] _links = _query.RunLinkQuery();

            if (_links.Count() == 2) //only 1 child and its parent
                Console.WriteLine("Parent ID: " + _links[1].TargetId);
            else
                Console.WriteLine("There is no parent for ID: " + _id);
        }
    }
}

=========================== for Relation Task-&gt; Something-&gt; Feature ========= ===

您可以使用树查询:

enter image description here

和这段代码:

using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QueryLinkedWIQL
{
    class Program
    {
        static void Main(string[] args)
        {
            WorkItemStore _wistore = new WorkItemStore("http://myserver/myCollection");

            int _id = 210;
            string _wiql = String.Format("SELECT [System.Id] FROM WorkItemLinks WHERE ([Source].[System.WorkItemType] = 'Feature') And ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') And ([Target].[System.Id] = {0}  AND  [Target].[System.WorkItemType] = 'Task') ORDER BY [System.Id] mode(Recursive,ReturnMatchingChildren)", _id);

            Query _query = new Query(_wistore, _wiql);

            WorkItemLinkInfo[] _links = _query.RunLinkQuery();

            if (_links.Count() > 1) //first item contains feature
                Console.WriteLine("Parent ID: " + _links[0].TargetId);
            else
                Console.WriteLine("There is no parent for ID: " + _id);
        }
    }
}

---------屏幕

查询:

enter image description here

调试:

enter image description here

enter image description here