1. 程式人生 > >EF中GroupBy擴展方法的簡單使用

EF中GroupBy擴展方法的簡單使用

擴展 col += get des str span div style

var ShopList = ShopService.GetEntities(x => x.IsDelete == false).OrderByDescending(x => x.Sort).GroupBy(x => new
{
x.Id,
x.CityName
}).Select(x => new
{
//Id = x.Key.Id,
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

EF中GroupBy擴展方法的簡單使用