Lamda将集合按某个字段分组后组成新的分组集合
本篇介绍如何使用SSIS和作业完成自动更新目标数据任务。
** 温馨提示:如需转载本文,请注明内容出处。**
本文链接:https://www.cnblogs.com/grom/p/9055605.html
实体类:
public class CarModelResponse { /// <summary> /// 年款 /// </summary> public int fldYearCotyName { get; set; } public List<CarModel> models { get; set; } }
/// <summary> /// 车型 /// </summary> public class CarModel { /// <summary> /// 车型ID /// </summary> public int fldModelID { get; set; } /// <summary> /// 车型名称 /// </summary> public string fldModelName { get; set; }/// <summary> /// 年款 /// </summary> public int fldYearCotyName { get; set; } /// <summary> /// 状态 0:启用 1:禁用 /// </summary> public int fldDisabled { get; set; } }
表达式:
public List<CarModelResponse> GetCarModel(int SeriesID) { var model = SqlHelper.GetCarModel(SeriesID); CarModelResponse response = new CarModelResponse(); var grouplist = model.GroupBy(x => x.fldYearCotyName).Select(x => new CarModelResponse { fldYearCotyName = x.Key, models = x.Where(g => g.fldYearCotyName == x.Key).ToList() }); return grouplist.ToList(); }
结果:

作者:Grom
出处:http://www.cnblogs.com/grom/
Where there is a will there is the way.
浙公网安备 33010602011771号