Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

.net - Retrieving work items and their linked work items in a single query using the TFS APIs

Does anyone know if it is possible to retrieve a list of work items and their linked work items in one trip from TFS using their TFS API web services?

At the moment, we are having to make a second call for each of the work items made during the first call, and is introducing a performace issue.

If that is not possibly, is there a way to peek at the type of the linked work item without retrieving them (e.g. See if it is a task or issue) ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The article you 're referring to in your answer presents with a method to do what you 're after, using WIQL. Certainly, not a bad choice.

Another way, in my opinion better, is to simply generate graphically the query that yields the results you 're after. You probably need a simple "Work Items and Direct Link":
enter image description here

Once you 've saved that you 'll be able to:

  1. Open the query in VS & Team Web Access
  2. Tie the query with Excel & work on WIs from within Excel
  3. Catch the query results with TFS-API.

For the latter part, supposing your query is named "MyLinkedQuery" and it resides under "Team Queries" of TeamProject "MyProj", you can do something like this:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace LinkedQueryResults
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSURL"));

            var workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));

            var project = workItemStore.Projects["MyProj"];
            QueryHierarchy queryHierarchy = project.QueryHierarchy;
            var queryFolder = queryHierarchy as QueryFolder;
            QueryItem queryItem = queryFolder["Team Queries"];
            queryFolder = queryItem as QueryFolder;

            if (queryFolder != null)
            {
                var myQuery = queryFolder["MyLinkedQuery"] as QueryDefinition;
                if (myQuery != null)
                {
                    var wiCollection = workItemStore.Query(myQuery.QueryText);
                    foreach (WorkItem workItem in wiCollection)
                    {
                        Console.WriteLine(workItem.Title); 
                    }
                }
            }       
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...