Search code examples
c#tfstfs-sdk

WIQL: How to get the content of a field of a work item returned by a query


I have to obtain the value of a field in a single work item. The query only returns one work item, because in my where clause I specify exaclty which Work Item Id I want. It's sort of a GetFieldByWorkItemId kind of method:

public double GetOriginalEstimate(object id)
{
    WorkItemCollection queryResults = workItemStore.Query(
        " SELECT [Original Estimate]" +
        " FROM WorkItems " +
        " WHERE [ID] = " + Convert.ToInt32(id)
        );

    return 0;
}

My two questions are:

  1. How can I get a work item from the WorkItemCollection queryResults by Id
  2. How can I get the value of the field that I'm interested in: [Original Estimate]

Solution

  • Rather than run a query, you can retrieve a single work item by it's ID:

    WorkItemStore.GetWorkItem(int id)["Original Estimate"]