C# 如何知道一个ID在WIQL TFS中是否有父ID?

C# 如何知道一个ID在WIQL TFS中是否有父ID?,c#,tfs,azure-devops,wiql,C#,Tfs,Azure Devops,Wiql,我有一个id,我想知道是否有parentid,通过对TFS进行C#编码。在我的TFS板中,有许多用户故事不包括功能? 我在TFS中的层次结构如下: Feature --->User Stories(u1,u2,u3) --->Tasks (t1,t2,t3) 有时,用户故事不包含功能您可以通过直接工作项查询获得此功能。您可以在VS中创建并保存到本地驱动器: 然后,您可以在保存的查询中找到查询文本: <?xml version="1.0" encoding="utf-8"?&

我有一个id,我想知道是否有
parentid
,通过对TFS进行C#编码。在我的TFS板中,有许多用户故事不包括
功能

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

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

有时,用户故事不包含
功能

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

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

<?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>
=================================对于关系任务->某些内容->功能============

您可以使用树查询:

该代码:

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);
        }
    }
}
---------屏风

查询:

调试:


有特定链接的用户故事???不,我想知道用户故事是否包含家长,这就是链接。如果不是,为什么不查看api docshow以了解它是父项还是子项?我可以知道任务是否具有功能ID吗?此示例使用任何具有已知ID(int _ID=175;)的工作项类型(任务、用户故事、bug)来查找其父项功能ID。“_links[1].TargetId”包含功能ID。我想查找任务功能ID它是在我的vsts帐户上测试的,主答案增加了屏幕。你能帮我吗
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);
        }
    }
}