给定某个产品 backlog 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;