首页 > 解决方案 > 快速循环 TFS 工作项或批量插入 TFS 工作项到 SQL 的快速方法

问题描述

我需要从 TFS 获取所有工作项并将每个细节存储到 SQL DB 中。我可以毫不费力地从 TFS 中获取所有内容。但没有找到将这些数据推送到 SQL Db 的完美方法。我考虑过遍历生成的对象并单独推送它们,但这非常耗时和资源消耗。所以期待一个完美的清洁解决方案。

这是我正在使用的代码

    public void  GetAllTfsWorkItems()
    {
        //List<string> projects = new List<string>();
        //projects = LoadProjectsList();
        var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(_uri));
        var workitemstore = new WorkItemStore(tpc);
        Query query = new Query(workitemstore, "select * from workitems where  [System.WorkItemType] in ('Epic','Bug','Feature','Product Backlog Item','Task') ");
        WorkItemCollection wic = query.RunQuery();
        List<string> PE = new List<string>();
        List<string> fields = new List<string>();
        foreach(WorkItem wi in wic)
        {
            PE.Add(wi.Title);
            var parentlink = wi.WorkItemLinks.Cast<WorkItemLink>().FirstOrDefault(x => x.LinkTypeEnd.Name == "Parent");
            WorkItem parentworkitem = null;
            int parentid;

            if(parentlink!=null)
            {
                parentid = parentlink.TargetId;
                //parentworkitem = workitemstore.GetWorkItem(parentlink.TargetId);

            }
        }

    }



public class TfsWorkItems
{
    public int ID { get; set; }
    public string WorkItemType { get; set; }
    public string Title { get; set; }
    public string AreaPath { get; set; }
    public string AssignedTo { get; set; }
    public string BoardColumn { get; set; }
    public string State { get; set; }
    public string Description { get; set; }
    public string IterationPath { get; set; }
    public string CreatedDate { get; set; }
    public string Tags { get; set; }
    public string AcceptanceCriteria { get; set; }
    public string BusinessValue { get; set; }
    public string Priority { get; set; }
    public string Effort    { get; set; }
    public string PCode { get; set; }
    public string Parent { get; set; }
    public string Project { get; set; }
    public string TeamName { get; set; }
    public string DomainName { get; set; }
}

循环大约需要 10-15 分钟才能完成。但我希望有一些更简单的解决方案,例如将 WorkItem 数组对象直接映射到我的自定义类 TFSWorkItems 以及将数据推送到一起的一些方法。请提出一个更简单的解决方案。截止日期快到了,因为我猜 2019 年时间过得很快。

请注意,TFS 中大约有 250k+ 个项目

标签: c#tfsazure-devopstfs-sdk

解决方案


推荐阅读