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

mac2022-06-30  33

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(); }

 

转载于:https://www.cnblogs.com/SeNaiTes/p/8877097.html

最新回复(0)