本文介绍了如何通过wiql c#asp.net获取工作项的所有字段详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我的TFS层次结构是这样的

bascially i hierarchy of my TFS is like this

P1
-> task1
-> task2
-> task3
-> task4
p1可以包含以下字段故事所有者,故事作者,分配给,状态,优先级,标题
和P1可以包含4个任务,我想使用p1字段(故事所有者,故事作者,分配给,状态,优先级和标题)来完成任务的所有详细信息.

P1
->task1
->task2
->task3
->task4
p1 cantains the following fields story owner,story author,assigned to,state,priorty,title
and P1 cantains 4 task i want all the details of task with p1 fields(story owner,story author,assigned to,state,priorty and title).

为此的代码我没有得到带有任务详细信息(故事所有者,故事作者,分配给,状态,优先级和标题)的p1字段.

code for this i am not getting p1 fields with it's task details(story owner,story author,assigned to,state,priorty and title).

var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("tfs url"));
                WorkItemStore workItemStore = new WorkItemStore(tpc);

                Query query = new Query(workItemStore, "SELECT * FROM WorkItems WHERE [System.TeamProject] = @project", new Dictionary<string, string>() { { "project", projectname } });

                WorkItemCollection wic = query.RunQuery();
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://apactfs.cbre.com:8080/tfs/cbre.apac.applications"));
                WorkItemStore workItemStore = new WorkItemStore(tpc);

                Query query = new Query(workItemStore, "SELECT * FROM WorkItems WHERE [System.TeamProject] = @project", new Dictionary<string, string>() { { "project", projectname } });

                WorkItemCollection wic = query.RunQuery();
foreach (WorkItem item in wic)
                {

                    info += String.Format("{0}\n", item.Title);
                }

推荐答案

您必须先通过单跳查询获取任务列表,然后再获取其详细信息.

You have to get the list of the tasks via one-hop query first and then get the detailed information for it.

TfsTeamProjectCollection TTPC = new TfsTeamProjectCollection(new Uri("http://xxx:8080/tfs/xxxCollection/"));
            WorkItemStore wis = TTPC.GetService<WorkItemStore>();
            string project = "projectname";
            string workitemid = "1";
            string wiql = $"SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM WorkItemLinks WHERE (Source.[System.TeamProject] = '{project}' and Source.[System.Id] = {workitemid}) and (Target.[System.TeamProject] = '{project}' and Target.[System.WorkItemType] = 'Task') ORDER BY [System.Id] mode(MustContain)";
            Query query = new Query(wis,wiql);
            WorkItemLinkInfo[] result = query.RunLinkQuery();
            List<WorkItem> tasks = new List<WorkItem> { };
            foreach (WorkItemLinkInfo wili in result)
            {
                if (wili.SourceId == 0)
                {
                    //Get the parent work item here.
                }
                else
                {
                    //Get the details for the linked tasks and add to tasks list.
                    tasks.Add(wis.GetWorkItem(wili.TargetId));
                }
            }

这篇关于如何通过wiql c#asp.net获取工作项的所有字段详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 17:30