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

时间:2018-04-18 19:59:18   收藏:0   阅读:620
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

 

原文:https://www.cnblogs.com/SeNaiTes/p/8877097.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!