This section describes how to query work items for use in two development definitions to obtain a work item list.
Query work items by using the Workitemstore.query method, which uses the same syntax as the SQL syntax:
Select [title]
From WorkItems
Where [Work Item Type]= ' Task ' and [assigned to] = ' Administrator '
Order BY [title]
We learn through several steps, first, we connect TFS services:
Tfsuri
uri Tfsuri = new Uri ("Http://pc-20130113jkun:8080/tfs");
Tfsteamprojectcollection projectcollection = new Tfsteamprojectcollection (Tfsuri);
WorkItemStore WorkItemStore = (workitemstore) projectcollection.getservice (typeof
(WorkItemStore));
Second, basic inquiries
Basic Query
workitemcollection queryresults = workitemstore.query (@)
select [title] from
WorkItems
Where [Work Item Type] = ' Bug ' ");
foreach (WorkItem item in QueryResults)
{
Console.WriteLine ("Work Item Name:" +item. Title+ "Work Item Description:" +item. Description);
}
Three, multiple conditions query and sorting
Console.WriteLine ("--------------------------
multiple criteria query and Sorting-------------------------");
Multi-condition query and sort
workitemcollection itemcollection = workitemstore.query (@ Select [title] FROM WorkItems
where [work item type] = ' Task ' and [assigned to] = ' Administrator ' order by [title] ';
foreach (WorkItem item in itemcollection)
{
Console.WriteLine ("Work Item Name:" + item.) Title + "Work Item Description:" + Item. Description);
}
Iv. Number of query results
Console.WriteLine ("--------------------------Number of query
results-------------------------");
Query result quantity
string querystring = @ "SELECT [title] FROM WorkItems Where [work item Type] = ' Bug '";
Query query = new query (workitemstore,querystring);
int numworkitems = query. Runcountquery ();
Console.WriteLine ("Number of work Items" + Numworkitems + "user Stories.");