TFS API : 四、工作项查询

本节将讲述如何查询工作项,将用户统计数据。

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

Select [标题]

from workitems

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

order by [标题]

  我们通过多个步骤来学习,

一、基本查询

//取出团队集合URI下的项目名称,如果团队集合为空则取默认集合下项目

  Uri tfsUri = new Uri("http://10.0.9.142:8080/tfs/web");//这种将会Calueng团队集合下项目

  TfsTeamProjectCollection server = new TfsTeamProjectCollection(tfsUri);

WorkItemStore workstore = server.GetService<WorkItemStore>();

  //基本查询

  WorkItemCollection queryResults = workstore.Query(@"Select  [标题]  From WorkItems Where [工作项类型] = 'Bug'");

  foreach (WorkItem item in queryResults)

  {

        Console.WriteLine(" 工作项名称:" + item.Title);

}

二、多条件查询和排序

WorkItemCollection itemcollection = workstore.Query(@"Select [标题] from workitems

      here [工作项类型]='Bug' and [指派给] in ('xxxxxx ') and [严重级别]='3 - Medium' order by [标题] ");

foreach (WorkItem item in itemcollection)

{

     Console.WriteLine(" 工作项名称:" + item.Title);

}

 

三、查询结果数量

 

string queryString = @" Select  [标题] From WorkItems where [工作项类型]='Bug' and [指派给] in ('v-杨瑞风')";

Query query = new Query(workstore, queryString);

int numWorkItems = query.RunCountQuery();

Console.WriteLine("工作项数量 " + numWorkItems);  

 

 

四、关于查询语句的条件

    在VS中的工作项,选择列选项,在这里可以编辑工作项目的显示内容,同样,这里面的列就是条件。因为我个人测试了很多大部分需要用来筛选的条件都和这里面有关系,但是因为数据的原因,很多条件没有办法测试,个人猜测,编辑查询语句的时候,条件只要和列名一样即可。

 

五、查询结果显示

原文地址:https://www.cnblogs.com/fenger-VIP/p/4607394.html