如何从 TFS API 中的产品待办事项列表项检索子任务列表?
给定某个产品待办事项 ID,我想以编程方式检索 PBI 子级任务的列表。
我知道任务中没有一个字段显示“Parent PBI Id”。我有一个正在运行的代码版本,但这真的很慢,因为我确实在客户端中执行了部分过滤。
看看我目前的表现:
string wiqlQuery =
string.Format(
"Select ID, [Remaining Work], State " +
"from WorkItems " +
"where (([Work Item Type] = 'Task')" +
" AND ([Iteration Path] = '{0}' )" +
" AND (State <> 'Removed')" +
" AND (State <> 'Done')) ",
sprint, storyId);
// execute the query and retrieve a collection of workitems
WorkItemCollection workItems = wiStore.Query(wiqlQuery);
if (workItems.Count <= 0)
return null;
var result = new List<TaskViewModel>();
foreach (WorkItem workItem in workItems)
{
var relatedLink = workItem.Links[0] as RelatedLink;
if (relatedLink == null) continue;
if (relatedLink.RelatedWorkItemId != storyId) continue;
Field remWorkField = (from field in workItem.Fields.Cast<Field>()
where field.Name == "Remaining Work"
select field).FirstOrDefault();
if (remWorkField == null) continue;
if (remWorkField.Value == null) continue;
var task = new TaskViewModel
{
Id = workItem.Id,
ParentPbi = relatedLink.RelatedWorkItemId,
RemainingWork = (double) remWorkField.Value,
State = workItem.State
};
result.Add(task);
}
return result;
Given a certain product backlog id, I want to programmatically retrieve a list of tasks that are child to the PBI.
I am aware that there's not one field in the task that says "Parent PBI Id". I have a version of code that is working, but that's really really slow, since I have do perform part of my filtering int the client.
See how I'm currently doing:
string wiqlQuery =
string.Format(
"Select ID, [Remaining Work], State " +
"from WorkItems " +
"where (([Work Item Type] = 'Task')" +
" AND ([Iteration Path] = '{0}' )" +
" AND (State <> 'Removed')" +
" AND (State <> 'Done')) ",
sprint, storyId);
// execute the query and retrieve a collection of workitems
WorkItemCollection workItems = wiStore.Query(wiqlQuery);
if (workItems.Count <= 0)
return null;
var result = new List<TaskViewModel>();
foreach (WorkItem workItem in workItems)
{
var relatedLink = workItem.Links[0] as RelatedLink;
if (relatedLink == null) continue;
if (relatedLink.RelatedWorkItemId != storyId) continue;
Field remWorkField = (from field in workItem.Fields.Cast<Field>()
where field.Name == "Remaining Work"
select field).FirstOrDefault();
if (remWorkField == null) continue;
if (remWorkField.Value == null) continue;
var task = new TaskViewModel
{
Id = workItem.Id,
ParentPbi = relatedLink.RelatedWorkItemId,
RemainingWork = (double) remWorkField.Value,
State = workItem.State
};
result.Add(task);
}
return result;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为标准,MSF Agile 中的团队项目附带一组查询。看一下“工作项目”-> '迭代 1' -> “迭代积压”。
将此查询另存为磁盘中的 WIQL 文件是完全可能的。
将其用作修改后的
wiqlQuery
应该可以使您免于进行大量过滤。编辑(回应评论:“好吧,我这样做了,但查询没有提到父项和链接(子)项之间的关系”):
我打开了默认“Iteration Backlog”:
检索相关项目的查询部分应该是这样
As a standard, team project in MSF Agile comes with a set of queries. Take a look at 'Work Items' -> 'Iteration 1' -> 'Iteration Backlog'.
Saving this query as WIQL file in your disk is absolutely possible.
Using it as a modified
wiqlQuery
should relieve you from a lot of the filtering you do.EDIT (in response to comment: "Ok, I did that, but the query doesn't mention the relationship between parent and linked (child) items"):
I opened the WIQL of a default "Iteration Backlog":
The part of the query that retrieves the related items should be this