2016-12-05 42 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;」 –

相關問題