0

我有以下代码来获取一些特定的工作项:

string workItemQueryString = "Select Id, State, Type From WorkItems Where [Work Item Type] = 'Code Review Request' And [Area Path] = 'abc' Order By [Changed Date] Desc";
var workItemQuery = new Query(workItemStore, workItemQueryString);
WorkItemCollection queryResults = workItemQuery.RunQuery();

此代码运行速度很快(< 1 秒)。但是,我还想获得一些额外的字段,例如“关联上下文类型”和“关联上下文”。

所以我使用这段代码获取这些字段:

var workItemDetails = queryResults.Cast<WorkItem>().Select(workItem => new WorkItemDetail
{
    WorkItem = workItem,
    AssociatedContextType = workItem.Fields.Contains("Associated Context Type") ? workItem.Fields["Associated Context Type"].Value : null,
    AssociatedContext = workItem.Fields.Contains("Associated Context") ? workItem.Fields["Associated Context"].Value : null
}).ToList();

但是这段代码运行速度非常慢(13 到 20 秒),在我看来,单独的查询(对于每个工作项?)被触发到 TFS 服务器以获取所有数据。

请注意,当我使用Parallel.ForEach语句时,代码会因异常而中断。

WorkItemCollection 中的 WorkItem 总数约为 2800。

4

1 回答 1

0

尝试改变:

AssociatedContextType = workItem.Fields.Contains("AssociatedContextType") ? workItem.Fields["AssociatedContextType"].Value : null,
AssociatedContext = workItem.Fields.Contains("AssociatedContext") ? workItem.Fields["AssociatedContext"].Value : null

至:

AssociatedContextType = workItem.Fields.Contains("Associated Context Type") ? workItem.Fields["Associated Context Type"].Value : null,
AssociatedContext = workItem.Fields.Contains("Associated Context") ? workItem.Fields["Associated Context"].Value : null
于 2016-12-06T07:36:21.133 回答