EF中GroupBy扩展方法的简单使用

 public ActionResult ShopInfo()
        {
            ViewBag.ShopList = ShopService.GetEntities(x => x.IsDelete == false).OrderByDescending(x => x.Sort).ToList();
            var ShopList = ShopService.GetEntities(x => x.IsDelete == false).GroupBy(x => new
            {
                x.CityName
            }).Select(x => new
            {
                Name = x.Key.CityName,
            }).ToList();

            string str = string.Empty;
            foreach (var item in ShopList)
            {
                str += ",'" + item.Name + "'";
            }
            ViewBag.Str = str.Substring(1);// 店名1,店名2,店名3
            return View();
        }

 

posted @ 2018-04-18 19:31  紫晶城  阅读(421)  评论(0编辑  收藏  举报