.net 使用 TFS API 在单个查询中检索工作项及其链接的工作项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10748412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Retrieving work items and their linked work items in a single query using the TFS APIs
提问by Prabu
Does anyone know if it is possible to retrieve a list of work items and their linked work itemsin one trip from TFS using their TFS API web services?
有谁知道是否可以使用他们的 TFS API Web 服务在一次旅行中从 TFS检索工作项列表及其链接的工作项?
At the moment, we are having to make a second call for each of the work items made during the first call, and is introducing a performace issue.
目前,我们不得不为第一次调用期间所做的每个工作项进行第二次调用,并且引入了性能问题。
If that is not possibly, is there a way to peek at the type of the linked work item without retrieving them (e.g. See if it is a task or issue) ?
如果这不可能,有没有办法在不检索链接的工作项的情况下查看它们的类型(例如,查看它是任务还是问题)?
采纳答案by Prabu
Found an articleregarding this issue.
It allows you to use a tree query, where you can get the parent item ids and it's linked items ids in one query. Using this, a second query can be used to get the actual detailed work item objects. Two queries to solve the issue.
它允许您使用树查询,您可以在其中获取父项 ID 及其在一个查询中的链接项 ID。使用它,可以使用第二个查询来获取实际的详细工作项对象。两个查询来解决这个问题。
Edit: I also wrote a postabout this on my blog.
编辑:我也写了一个帖子关于这个我的博客上。
回答by pantelif
The articleyou 're referring to in your answer presents with a method to do what you 're after, using WIQL. Certainly, not a bad choice.
Another way, in my opinion better, is to simply generate graphically the query that yields the results you 're after. You probably need a simple "Work Items and Direct Link":
Once you 've saved that you 'll be able to:
您在回答中引用的文章提供了一种使用WIQL完成您所追求的事情的方法。当然,不是一个糟糕的选择。
在我看来更好的另一种方法是简单地以图形方式生成查询,从而产生您想要的结果。您可能需要一个简单的“工作项和直接链接”:
保存后,您将能够:
- Open the query in VS & Team Web Access
- Tie the query with Excel & work on WIs from within Excel
- Catch the query results with TFS-API.
- 在 VS & Team Web Access 中打开查询
- 将查询与 Excel 联系起来并在 Excel 中处理 WI
- 使用 TFS-API 捕获查询结果。
For the latter part, supposing your query is named "MyLinkedQuery" and it resides under "Team Queries" of TeamProject "MyProj", you can do something like this:
对于后一部分,假设您的查询名为“MyLinkedQuery”并且它位于 TeamProject“MyProj”的“Team Queries”下,您可以执行以下操作:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace LinkedQueryResults
{
class Program
{
static void Main()
{
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSURL"));
var workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
var project = workItemStore.Projects["MyProj"];
QueryHierarchy queryHierarchy = project.QueryHierarchy;
var queryFolder = queryHierarchy as QueryFolder;
QueryItem queryItem = queryFolder["Team Queries"];
queryFolder = queryItem as QueryFolder;
if (queryFolder != null)
{
var myQuery = queryFolder["MyLinkedQuery"] as QueryDefinition;
if (myQuery != null)
{
var wiCollection = workItemStore.Query(myQuery.QueryText);
foreach (WorkItem workItem in wiCollection)
{
Console.WriteLine(workItem.Title);
}
}
}
}
}
}

