none
MVC LINQ TO SQL查询超时 RRS feed

  • 问题

  • if (a1 == "10" && a2 == "11")
                    {
                        var State = from a in storeDb.Sys_Param where a.ParamType == 505 select a;//查询馆藏状态
                        Dictionary<string, string> DicLtlx = new Dictionary<string, string>();
                        for (int i = 0; i < State.Count(); i++)  //循环大分类
                        {
                            int StateID = State.ToList()[i].ParamIndex;  //馆藏状态
                            string StateName = State.ToList()[i].ParamName;
                            int zs = 0;
                            int cs = 0;
                            decimal zj = 0;
                            var query1 = from p in collection//查询种数
                                         join q in Biblios on p.RecordID
                                         equals q.RecordID
                                         where p.State == StateID
                                         group p by p.RecordID into g
                                         select new
                                         {
                                             recordid = g.Key,
                                             count = g.Count()
                                         };
                            var query2 = from p in collection//查询总价
                                         join q in Biblios on p.RecordID
                                         equals q.RecordID
                                         where p.State == StateID
                                         group p by p.CollectionID into g
                                         select new
                                         {
                                             VolumeSinglePrice = g.Key,
                                             count = g.Count()
                                         };
                            zs = query1.ToList().Distinct().Count();//得到种数
                            cs = query1.ToList().Count();
                            foreach (var zj1 in query2)//遍历得到总价--在程序运行到这时报超时错误,有7w条数据,在只有几条数据的时候也报超时错误
                            {
                                for (int k = 0; k < zj1.count; k++)
                                {
                                    zj = zj + zj1.VolumeSinglePrice;
                                }
                            }
                            DicLtlx.Add(StateName, zs + "#" + cs + "#" + zj ); 
                        }
                        ViewData["aaa"] = DicLtlx;
                    ExcelList = DicLtlx;
                    }

    2013年1月28日 7:57