请问你们一个有关问题,麻烦帮忙看看,多谢

请教你们一个问题,麻烦帮忙看看,谢谢
现在我在一个页面展示3个table来显示最近30天相应订单的数量,我现在写的这种逻辑是可以实现的,只不是循环起来花费的时间比较多,刚才测了一下,发现一个表耗时差不多7s左右,所以想请教大家有没有其他更好点的方法,或者我的代码哪里可以优化的,万分感激。我下面会展示代码截图和源代码:
现在显示效果图:请问你们一个有关问题,麻烦帮忙看看,多谢
现在显示的代码截图是其中一个表的循环代码逻辑,其他两个表获取数据的方法和这个也差不多:
请问你们一个有关问题,麻烦帮忙看看,多谢
源码:
  int producedaycount = 30;
            if (datetype == "producetime")
            {
                producedaycount = days == 0 ? 30 : days;
            }

            for (int i = 0; i <= producedaycount; i++)
            {
                string time = string.Empty;
                if (datetype == "producetime")//下单生产时间
                {
                    time = endtime == null ? DateTime.Now.AddDays(-i).ToShortDateString() : endtime.Value.AddDays(-i).ToShortDateString();
                }
                else
                {
                    time =DateTime.Now.AddDays(-i).ToShortDateString();
                }

                int? count = OrderProduceServices.StatistiCount(DateTime.Parse(time), productList, factoryList);

                //有数据的才需要
                if (count > 0)
                {
                    Dictionary<string, string> data = new Dictionary<string, string>();

                    data.Add("date", time);
                    data.Add("count", count.ToString());

                    list.Add(data);
                }
                list = list.OrderBy(x => DateTime.Parse(x["date"])).ToList();

            }


StatistiCount()方法具体逻辑:
  public int? Statistics(DateTime todayBeginTime, DateTime todayEndTime, List<int> productList, List<int?> factoryList)
        {
            int? count = 0;
            List<int?> factory = new List<int?>();

            if (factoryList.Count == 1)
            {
                factory = GetOrderFactory(factoryList[0].ToString());
                string factorytype = factoryList[0].ToString();

                count = (from op in DbContext.OrderProduce
                         where op.ProduceTime >= todayBeginTime && op.ProduceTime <= todayEndTime &&
                         productList.Contains((int)op.OrderDetail.ProductType) &&
                         (op.FactoryType == factorytype || factory.Contains(op.PaperPrint) ||
                         factory.Contains(op.CoverPrint) || factory.Contains(op.Binding))
                         select op.Count).Sum();
            }
            else
            {
                count = (from op in DbContext.OrderProduce
                         where op.ProduceTime >= todayBeginTime && op.ProduceTime <= todayEndTime &&
                         productList.Contains((int)op.OrderDetail.ProductType)
                         select op.Count).Sum();
            }

            return count;
        }

------解决思路----------------------
你这样每个日期单独统计,那要连接多少次数据库啊……
你这个可以通过sql的group来预先按日期范围进行汇总,然后将结果返回,这样只要连三次数据库,然后再在程序里面对取到的集合进行循环