C# TFS API - 如何从特定团队项目中获取工作项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9266437/
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
TFS API - How to fetch work item(s) from specific Team Project
提问by JF Beaulieu
I am trying to query a single team project in the main TfsTeamProjectCollectionwhich contains 194 Team Projects in total. I know exactly how to get a WorkItemby Id from a WorkItemStore. The thing is, that by doing this, the API searches in ALLof the projects in the collection and the query takes about a minute. This is way too slow, there must be a way to query work items directly from a single team project ? Here is the code I have:
我正在尝试查询主要的单个团队项目,TfsTeamProjectCollection其中总共包含 194 个团队项目。我确切地知道如何WorkItem从WorkItemStore. 问题是,通过这样做,API 会在集合中的所有项目中进行搜索,并且查询大约需要一分钟。这太慢了,必须有一种方法可以直接从单个团队项目中查询工作项吗?这是我的代码:
private Uri collectionUri;
private TfsTeamProjectCollection projectCollection;
private WorkItemStore workItemStore;
public Project GetTeamProject()
{
projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(collectionUri);
workItemStore = projectCollection.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects[TFS_PROJECT_KEY];
return teamProject;
}
Now that I have the Team Project I'm interested in, how can I query for work items by ID or just get all work items in this project ?
现在我有了我感兴趣的团队项目,如何通过 ID 查询工作项或仅获取该项目中的所有工作项?
采纳答案by jessehouwing
It's probably most efficient to use a query to find the workitemsyou're interested in. You can add a Where project = '@Project' to the query to limit the scope to just that project. By first calling BeginQuery and then EndQuery you'll get a workitem collection for just the items you were looking for.
使用查询来查找您感兴趣的工作项可能是最有效的。您可以向查询添加 Where project = '@Project' 以将范围限制为该项目。通过首先调用 BeginQuery 然后调用 EndQuery,您将获得仅包含您正在查找的项目的工作项目集合。
The easiest way to get the required wql query is to create a query in Team Explorer, then use file->save as (in edit mode) to save it to file. Open that file in Notepad to copy the query out of there.
获取所需 wql 查询的最简单方法是在团队资源管理器中创建一个查询,然后使用文件->另存为(在编辑模式下)将其保存到文件中。在记事本中打开该文件以将查询复制出来。
Alternatively you can use the WorkItemStore.Query methoddirectly to achieve the same thing.
或者,您可以直接使用WorkItemStore.Query 方法来实现相同的目的。
回答by pantelif
You could try something like this for getting all WIs within teamProject:
您可以尝试这样的方法来获取所有 WI teamProject:
WorkItemCollection workItemCollection = workItemStore.Query(
" SELECT [System.Id], [System.WorkItemType],"+
" [System.State], [System.AssignedTo], [System.Title] "+
" FROM WorkItems " +
" WHERE [System.TeamProject] = '" + teamProject.Name +
"' ORDER BY [System.WorkItemType], [System.Id]");
And this to get a specific WorkItem ID:
这是为了获取特定的 WorkItem ID:
WorkItem workItem = workItemStore.GetWorkItem(555);

