c#WIQL查询获取所有不同的迭代路径
问题描述:
我试图通过使用wiql查询来获取团队项目的所有不同迭代路径。c#WIQL查询获取所有不同的迭代路径
我实际的解决方案如下:
我用这个查询
public static readonly string IterationPathsQuery = @"SELECT [System.IterationPath] FROM workitems
WHERE[System.WorkItemType] = 'Requirement'
OR[System.WorkItemType] = 'Feature'";
要获得所有相关的工作项和遍历它们把所有的不同迭代路径。
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);
}
}
但是这个解决方案并没有很好的性能。 有没有办法只查询使用的不同迭代路径?我已经读过“不同”并不支持,但也许有一种方法我还没有考虑。
答
WIQL查询无法过滤不同的迭代路径。这里有两种方案:
您可以将查询导出到Excel并使用Excel RemoveDuplicates方法来筛选不同的迭代路径。
-
您可以获取迭代路径列表,然后使用LINQ删除重复项和获取不同记录。检查this website上的代码片段。
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; } } }
+0
谢谢! 替代方案2显着提高了我方法的性能。 – Goldi
你想获得该项目的一些具体工作项目的所有迭代路径或只是不同的迭代路径? –