统计一个栏目中的主题数

/// <summary>
        /// 统计数据
        /// </summary>
        /// <returns></returns>
        public List<plateNum> GetListPageForClassCount()
        {
            var classcount = from a in db.BBS_Class
                             select a;

            List<plateNum> list = new List<plateNum>();
            foreach (BBS_Class clssa in classcount)
            {
                var platecount = (from a in db.BBS_Class
                                  join b in db.BBS_Plate
                                  on a.ID equals b.ClassID into classtoplate
                                  from b in classtoplate.DefaultIfEmpty()
                                  select a).Where(o => o.ID.Equals(clssa.ID));

                var themecount = (from a in db.BBS_Class
                                  join b in db.BBS_Plate
                                  on a.ID equals b.ClassID into classtoplate
                                  from b in classtoplate.DefaultIfEmpty()

                                  join c in db.BBS_Theme
                                  on b.ID equals c.PlateID into platetotheme
                                  from c in platetotheme.DefaultIfEmpty()
                                  select a).Where(o => o.ID.Equals(clssa.ID));

                var postcount = (from a in db.BBS_Class
                                 join b in db.BBS_Plate
                                 on a.ID equals b.ClassID into classtoplate
                                 from b in classtoplate.DefaultIfEmpty()

                                 join c in db.BBS_Theme
                                 on b.ID equals c.PlateID into platetotheme
                                 from c in platetotheme.DefaultIfEmpty()

                                 join d in db.BBS_Post
                                 on c.ID equals d.ThemeID into themetopost
                                 from d in themetopost.DefaultIfEmpty()
                                 select a).Where(o => o.ID.Equals(clssa.ID));


                plateNum pnum = new plateNum();
                pnum.ID = clssa.ID;
                pnum.ClassName = clssa.Name;
                pnum.platenum = platecount.Count();
                pnum.themenum = themecount.Count();
                pnum.postnum = postcount.Count();

                list.Add(pnum);
            }

            return list;
        }

 

posted @ 2013-01-09 09:18  南潇湘  阅读(215)  评论(0编辑  收藏  举报