我有以下代码来获取一些特定的WorkItems:
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秒)。但是我也希望得到一些额外的字段,例如&#34; Associated Context Type&#34;和&#34;相关语境&#34;。
所以我使用这段代码得到那些字段:
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。
答案 0 :(得分: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