2个Linq查询可以并行运行吗?

By simon at 2018-02-28 • 0人收藏 • 47人看过

我有2个Linq查询,第1个Linq查询返回1148条记录和第2个返回 6667条记录。他们需要8分钟的执行时间。是第没有任何方法可以制作它们 并行运行速度更快?

var productbacklogworkitem =
               (from w in workItemcollectionList where w.Type.Name == "Product Backlog Item" select new {
                   Id = w.Id,
                   Name = w.Title,
                   FID = (w.WorkItemLinks.Count > 0) ? ((w.WorkItemLinks[0].LinkTypeEnd.Name.ToString() != "Child") ? w.WorkItemLinks[0].TargetId : 0) : 0,
                   Type = w.Type.Name,
                   State =w.State,
                   priorty = Convert.ToInt32(w.Fields["Priority"].Value),
                   Size = Convert.ToInt32(w.Fields["Effort"].Value),
                   StoryPoints = Convert.ToInt32(w.Fields["Story Points"].Value),
                   DoneStatus = w.Fields["Done Status"].Value.ToString(),
                   StoryOwner = w.Fields["Story Owner"].Value.ToString(),
                   Assignedto = w.Fields["Assigned To"].Value.ToString(),
                   StoryAuthor = w.Fields["Story Author"].Value.ToString(),
                   IterationPath = w.IterationPath
               }).ToList();
            var taskbugsworkitem =
             (from w in workItemcollectionList where (w.Type.Name == "Task" || w.Type.Name == "Bug") && (w.WorkItemLinks.Count > 0)   select new {
                 Id = w.Id,
                 Name = w.Title,
                 Type = w.Type.Name,
                 Storyid =  w.WorkItemLinks[0].TargetId,
                 status = w.State,
                 IterationPath = w.IterationPath,
                 Assignedto = w.Fields["Assigned To"].Value.ToString(),
                 priorty = Convert.ToInt32(w.Fields["Priority"].Value),
                 effort = Convert.ToInt32(w.Fields["effort"].Value),
                 Completed = (w.Type.Name== "Task") ? Convert.ToInt32(w.Fields["Completed"].Value):0
             }) .ToList();

1 个回复 | 最后更新于 2018-02-28
2018-02-28   #1

您可以使用实体上的AsParallel()来尝试PLINQ

var productbacklogworkitem =
               (from w in workItemcollectionList.AsParallel() where w.Type.Name == "Product Backlog Item" select new {
                   Id = w.Id,
                   Name = w.Title,
                   FID = (w.WorkItemLinks.Count > 0) ? ((w.WorkItemLinks[0].LinkTypeEnd.Name.ToString() != "Child") ? w.WorkItemLinks[0].TargetId : 0) : 0,
                   Type = w.Type.Name,
                   State =w.State,
                   priorty = Convert.ToInt32(w.Fields["Priority"].Value),
                   Size = Convert.ToInt32(w.Fields["Effort"].Value),
                   StoryPoints = Convert.ToInt32(w.Fields["Story Points"].Value),
                   DoneStatus = w.Fields["Done Status"].Value.ToString(),
                   StoryOwner = w.Fields["Story Owner"].Value.ToString(),
                   Assignedto = w.Fields["Assigned To"].Value.ToString(),
                   StoryAuthor = w.Fields["Story Author"].Value.ToString(),
                   IterationPath = w.IterationPath
               }).ToList();
            var taskbugsworkitem =
             (from w in workItemcollectionList.AsParallel() where (w.Type.Name == "Task" || w.Type.Name == "Bug") && (w.WorkItemLinks.Count > 0)   select new {
                 Id = w.Id,
                 Name = w.Title,
                 Type = w.Type.Name,
                 Storyid =  w.WorkItemLinks[0].TargetId,
                 status = w.State,
                 IterationPath = w.IterationPath,
                 Assignedto = w.Fields["Assigned To"].Value.ToString(),
                 priorty = Convert.ToInt32(w.Fields["Priority"].Value),
                 effort = Convert.ToInt32(w.Fields["effort"].Value),
                 Completed = (w.Type.Name== "Task") ? Convert.ToInt32(w.Fields["Completed"].Value):0
             }) .ToList();
有关更多信息,请参阅:

登录后方可回帖

Loading...