【问题标题】:c# WIQL Query to get all different Iteration Pathsc# WIQL 查询以获取所有不同的迭代路径
【发布时间】:2016-08-18 15:13:17
【问题描述】:

我正在尝试通过使用 wiql 查询来获取我们团队项目的所有不同迭代路径。

我的实际解决方案如下:

我使用这个查询

    public static readonly string IterationPathsQuery = @"SELECT [System.IterationPath] FROM workitems
        WHERE[System.WorkItemType] = 'Requirement'
        OR[System.WorkItemType] = 'Feature'";

获取所有相关的 WorkItems 并遍历它们以获得所有不同的迭代路径。

private void FillIterationPathComboBox(WorkItemStore wiStore)
{
    WorkItemCollection wiCollection = wiStore.Query(Constants.IterationPathsQuery);
    var paths = new List<string>();

    ...
    foreach (WorkItem wi in wiCollection)
    {
        ...

        if (!String.IsNullOrEmpty(wi.IterationPath) && !paths.Contains(wi.IterationPath))
        {
            paths.Add(wi.IterationPath);
        }
    }

    foreach (string path in paths)
    {
        IterationPathComboBox.Items.Add(path);
    }
}

但是这个解决方案的性能并不好。 有没有办法只查询使用的不同迭代路径?我已经读过不支持“distinct”,但也许有一种我还没有想到的方法。

【问题讨论】:

  • 您想获取项目中的所有迭代路径,还是只获取某些特定工作项的不同迭代路径?

标签: c# performance tfs wiql


【解决方案1】:

WIQL 查询无法过滤不同的迭代路径。这里有两种选择:

  1. 您可以将查询导出到 Excel,并使用 Excel RemoveDuplicates 方法过滤不同的迭代路径。

  2. 您可以获取迭代路径列表,然后使用 LINQ 删除重复项并获取不同记录。检查this website 上的代码 sn-p。

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    
    namespace AbundantCode  
    {
        internal class Program
        {
            //How to Remove Duplicates and Get Distinct records from List using LINQ ?
    
            private static void Main(string[] args)
            {
                List<Employee> employees = new List<Employee>()
    {
    
    new Employee { EmpID = 1 , Name ="AC"},
    new Employee { EmpID = 2 , Name ="Peter"},
    new Employee { EmpID = 3 , Name ="Michael"},
    new Employee { EmpID = 3 , Name ="Michael"}
    };
    
     //Gets the Distinct List
     var DistinctItems = employees.GroupBy(x => x.EmpID).Select(y => y.First());
                foreach (var item in DistinctItems)
                Console.WriteLine(item.Name);
                Console.ReadLine();
            }
        }
    
        public class Employee
        {
            public string Name { get; set; }
            public int EmpID { get; set; }
        }
    }
    

【讨论】:

  • 谢谢!备选方案 2 显着提高了我的方法的性能。
猜你喜欢
  • 2018-08-12
  • 1970-01-01
  • 2015-03-13
  • 2015-08-14
  • 2018-09-01
  • 2020-04-30
  • 2015-07-03
  • 2017-06-10
  • 2021-11-25
相关资源
最近更新 更多