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

时间:2018-02-26 09:51:55

标签: tfs wiql

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

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不存在”。我怎么能解决它?

1 个答案:

答案 0 :(得分:4)

您无法使用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);
                }
            }

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