Welcome

首页 / 软件开发 / 数据结构与算法 / TFS工作项查询

TFS工作项查询2013-11-30 cnblogs 程兴亮本节将讲述如何查询工作项,用于二次开发中定义获取工作项列表。

使用WorkItemStore.Query方 法进行查询工作项,其使用的语法和SQL语法类似:

Select [标题]

from workitems

where [工作项类型]="任务" and [指派给] = "administrator"

order by [标题]

我们通过多个步骤来学习,一、我们连接TFS服务 :

//TFSURIUri tfsUri = new Uri("http://pc-20130113jkun:8080/tfs");TfsTeamProjectCollection projectCollection = new TfsTeamProjectCollection(tfsUri);WorkItemStore workItemStore = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore));
二、基本查询

//基本查询WorkItemCollection queryResults = workItemStore.Query(@"Select[标题] From WorkItemsWhere [工作项类型] = "Bug" ");foreach (WorkItem item in queryResults){Console.WriteLine(" 工作项名称:"+item.Title+" 工作项描述:"+item.Description);}
三、多条件查询和排序

Console.WriteLine("--------------------------多条件查询和排序-------------------------");//多条件查询和排序WorkItemCollection itemcollection = workItemStore.Query(@"Select [标题] from workitems where [工作项类型]="任务" and [指派给] = "administrator" order by [标题] ");foreach (WorkItem item in itemcollection){Console.WriteLine(" 工作项名称:" + item.Title + " 工作项描述:" + item.Description);}
四、查询结果数量

Console.WriteLine("--------------------------查询结果数量-------------------------");//查询结果数量string queryString = @" Select[标题] From WorkItems Where [工作项类型] = "Bug"";Query query = new Query(workItemStore,queryString); int numWorkItems = query.RunCountQuery();Console.WriteLine("工作项数量 " + numWorkItems + " user stories.");