分组时超时

时间:2015-09-17 14:38:16

标签: c# linq

我有一个报告屏幕,我在DB中按超过200 MB的数据进行分组,有时我会超时,有时会运行完成。

如何优化或加快速度?

以下是我的代码:

    public ActionResult CleanReport()
    {
        var count = _db.Surveys.AsNoTracking().Count();

        var result = _db.Surveys.AsNoTracking().GroupBy(x => x.Clean).Select(group => new { Clean = group.Key, Count = group.Count() });

        var items = new List<PieChartModel>();

        foreach (var item in result)
        {
            if (item.Clean.HasValue == false)
            {
                continue;
            }

            var chartModel = new PieChartModel();

            if (item.Clean == Clean.IdareEder)
            {
                chartModel.color = "#F7464A";
                chartModel.highlight = "#FF5A5E";
            }

            if (item.Clean == Clean.Iyiydi)
            {
                chartModel.color = "#46BFBD";
                chartModel.highlight = "#5AD3D1";
            }

            if (item.Clean == Clean.Kötüydü)
            {
                chartModel.color = "#642EFE";
                chartModel.highlight = "#642EFE";
            }

            if (item.Clean == Clean.CevapYok)
            {
                chartModel.color = "#FFCC00";
                chartModel.highlight = "#FFCC66";
            }

            chartModel.label = item.Clean.Value.DisplayName();

            double per = (item.Count * 100.0) / count;
            chartModel.value = (int)Math.Round(per);

            items.Add(chartModel);
        }

        return Json(items, JsonRequestBehavior.AllowGet);
    }

0 个答案:

没有答案