【问题标题】:How to query Work Item links with specified comment using WIQL如何使用 WIQL 查询带有指定注释的工作项链接
【发布时间】:2018-02-27 11:25:52
【问题描述】:

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

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();

尝试运行此代码时发生异常“字段 System.Links.Comment 不存在”。我该如何解决?

【问题讨论】:

    标签: tfs wiql


    【解决方案1】:

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

    你需要使用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);
                    }
                }
    

    然后在workitem.Relations中找到带有relation.Attributes["comment"]的指定评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-03
      • 2015-06-20
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 2012-12-26
      • 2010-11-25
      相关资源
      最近更新 更多