代码之家  ›  专栏  ›  技术社区  ›  Hopeless

如何使用WIQL查询具有指定注释的工作项链接

  •  3
  • Hopeless  · 技术社区  · 8 年前

    我需要一个快速的方法来获得一个链接列表过滤的链接评论。 有一个代码:

    var linkCommentFilter = "Some link comment";
    const string queryString = @"SELECT [System.Id]
                                   FROM workItemlinks
                                   WHERE [System.Links.LinkType] = 'Tested By'
                                   AND [System.Links.Comment] = '{0}'
                                   AND ([Source].[System.Id] IN ({1}))";
    
    var query = new Query(store, string.Format(queryString, 
        linkCommentFilter,
        string.Join(",", wiIds)));
    var result = query.RunLinkQuery().ToArray();
    

    尝试运行此代码时,出现异常“field System.Links.Comment不存在”。我怎样才能修复它?

    1 回复  |  直到 8 年前
        1
  •  4
  •   Cece Dong - MSFT    8 年前

    无法使用WIQL查询具有指定注释的工作项链接,因为没有 System.Links.Comment TFS中的字段。

    您需要使用TFS rest api get a list of work items with links and attachments ,请检查下面的示例代码:

     public List<WorkItem> GetWorkItemsWithLinksAndAttachments()
            {
                int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 };
    
                VssConnection connection = Context.Connection;
                WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
    
                List<WorkItem> workitems = workItemTrackingClient.GetWorkItemsAsync(workitemIds, expand: WorkItemExpand.Links | WorkItemExpand.Relations).Result;
    
                foreach(var workitem in workitems)
                {
                    Console.WriteLine("Work item {0}", workitem.Id);
    
                    foreach (var relation in workitem.Relations)
                    {
                        Console.WriteLine("  {0} {1}", relation.Rel, relation.Url);
                    }
                }
    

    然后使用查找指定的注释 relation.Attributes["comment"] 在里面 workitem.Relations .