Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Essentials of Work Item Queries

Essentials of Work Item Queries

You can use the work item object model to construct SQL-like query statements in the Work Item Query Language (WIQL). WIQL can select work items assigned to a particular person, work items that contain specific title words, or work items that fulfill other criteria.

The power of the work item store comes from the ability to query its contents. You can use it to build more complex queries than are supported in the query builder user interface found in the Team Explorer.

These queries can be run against a WorkItemStore in several ways.

You can call the query and pass it a string containing your query:

WorkItemCollection result = m_store.Query(editQuery.Text, context);

You can call all the queries and pass it a string containing your query context. The context contains information such as dayprecision.

WorkItemCollection result = m_store.Query(editQuery.Text, context);

You can also use Query object to encapsulate and run queries. You can construct these objects with the Query class constructors such as these:

public Query(WorkItemStore store, string wiql)
public Query(WorkItemStore store, string wiql, IDictionary context)

Queries against the WorkItemStore can take a significant amount of time to complete. You can run them and then cancel them asynchronously using query methods such as these:

public Microsoft.TeamFoundation.Client.ICancelableAsyncResult BeginQuery()
public Microsoft.TeamFoundation.Client.ICancelableAsyncResult BeginQuery(System.AsyncCallback callBack)
public Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemCollection EndQuery(Microsoft.TeamFoundation.Client.ICancelableAsyncResult car)

The results of a query are held in a WorkItemCollection that behaves like a read-only collection of WorkItem objects.

For improved performance, a WorkItemCollection is returned from a query page’s results. Each page contains 50 WorkItem objects and additional WorkItem objects are paged in, 50 at a time, as needed.

Queries can be persisted on the Team Foundation Server using the StoredQueryCollection class. After it is saved, the query appears in the Team Explorer. Other team members can then edit and run the query.

Community Additions

© 2015 Microsoft