使用Group By的LINQ性能优化

时间:2014-07-11 22:36:58

标签: c# performance linq optimization group-by

我在C#LINQ中有一个group by子句,执行时间超过5分钟。在生产环境中因大规模数据而超时。有没有办法优化这个LINQ查询?感谢任何帮助。

var qFilingReview = (from x in FilingReviewsList
                    group x by new { x.filingAnswer.Grouping, x.filingAnswer.Instructions, x.filingReview.Name, x.filingQuestion.Number } into grp
                    select new { result = grp.FirstOrDefault() })
                         .ToList()
                         .OrderBy(k => k.result.filingQuestion.Id)
                         .ThenByDescending(k => k.result.filingAnswer.Id);

1 个答案:

答案 0 :(得分:3)

起初我认为你必须删除不必要的ToList()调用。

相关问题