2016-12-05 17 views
0

我已经有下面的代码得到一些具体的工作项目:如何在一次调用中使用WIQL从WorkItem中获取字段以加快速度?

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秒)。不过,我也想获得一些额外的字段,如“关联的上下文类型”和“关联的上下文”。

所以我用这个代码获取Get这些领域:

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工作项的总数大约是2800

+0

哪个TFS的版本,您使用的?我的TFS 2015.3中的工作项目较少,而且我看不到代码太慢。在VS或Web Access中运行查询时速度慢吗? –

回答

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 
+0

对不起,这是一个复制粘贴错误。我实际上使用了“关联上下文类型”和“关联上下文”。 –

+0

我可以加快设置页面大小的设置:“queryResults.PageSize = 200;” –

相关问题