WIQL 查询以获取工作项下的所有项 [英] WIQL query to get all item under a workitem

查看:31
本文介绍了WIQL 查询以获取工作项下的所有项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找可以从区域路径返回所有工作项及其关系的查询.

I am looking for a query where i can return all work items and their relation from a area path.

例如:项目 1

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

i need all Featured all Userstories mapped to it all workitem and Bug mapped to userstories,

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

in short if i took a bug from the object i need somthing like parent id where i can match with the userstory.

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 是否正确引用时,当我重新编写这样的查询时,查询工作正常

when i checked the dll's are refereed correctly and when i re wrote the query like this the query is working fine

 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.如何得到那个.提前致谢.

but this query result does not give the relation ship that if a work item mapped as a child to other i need parent id in the work item object. how to get that. Thanks in advance.

推荐答案

你可以试试下面的查询:

You can try below query:

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

Install Nuget Package Microsoft.TeamFoundationServer.ExtendedClient for the project.

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:

Besides, you can also use Wiql Editor. If you want to get all the parent workitems (IDs) from a specific child work item (ID), you can use below 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)

这篇关于WIQL 查询以获取工作项下的所有项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆