WIQL 查询以获取工作项下的所有项目

WIQL query to get all item under a workitem

我正在寻找一个可以return 区域路径中的所有工作项及其关系的查询。

例如:项目 1

我需要所有精选所有用户故事映射到它所有工作项和错误映射到用户故事,

简而言之,如果我从对象中获取错误,我需要像父 ID 这样的东西,我可以在其中与用户故事匹配。

string query1 = " SELECT * FROM WorkItemLinks " +
                    " WHERE ( [System.IterationPath] Under 'iteration1' )" +
                    " AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
                    " ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";

抛出如下错误

An exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll but was not handled in user code

Additional information: TF51005: The query references a field that does not exist. The error is caused by «[System.IterationPath]».

当我检查 dll 是否被正确引用时,当我像这样重新编写查询时,查询工作正常

 string query = " SELECT * FROM WorkItems"+
                           " WHERE  ( [System.IterationPath] Under 'iteration1' )" +
                           //" AND  ([System.State] = 'Active' OR  [System.State] = 'Assessed' ) "+
                           //" AND  ( [Microsoft.VSTS.Scheduling.StartDate] <= '09/13/2017' AND  [Microsoft.VSTS.Scheduling.FinishDate] >= '09/13/2017' )"+
                           " ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";

但是这个查询结果没有给出这样的关系:如果一个工作项作为子项映射到另一个我需要工作项对象中的父 ID。如何得到它。提前致谢。

您可以尝试以下查询:

为项目安装 Nuget 包 Microsoft.TeamFoundationServer.ExtendedClient

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;

namespace _0925_WIQL
{
    class Program
    {
        static void Main(string[] args)
        {
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
                  new Uri("http://server:8080/tfs/CollectionLC"));
            WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore));


            string query1= " SELECT * FROM WorkItemLinks " +
                    " WHERE ( Source.[System.IterationPath] Under 'TeamProject\Iteration 1' )" +
                    " AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
                    " ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";

            Query query = new Query(workItemStore, query1);
            WorkItemLinkInfo[] witLinkInfos = query.RunLinkQuery();

            foreach (WorkItemLinkInfo witinfo in witLinkInfos)
            {

                .......
            }

此外,您还可以使用Wiql Editor。如果您想从特定的子工作项 (ID) 获取所有父工作项 (ID),您可以使用以下 WIQL:

SELECT                      
        [System.Id],
        [System.WorkItemType],
        [System.Title],
        [System.AssignedTo],
        [System.State]
FROM workitemLinks
WHERE ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND ([Target].[System.Id] = 25)
ORDER BY [System.Id]
MODE (Recursive, ReturnMatchingChildren)