从List分组后重新组织数据
生活随笔
收集整理的這篇文章主要介紹了
从List分组后重新组织数据
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
///從List分組后從重組織數(shù)據(jù)var res = result.GroupBy(s => new
{s.LegalUnitID,s.TYPE_CD,s.TYPE_NAME,s.TYPE_NAME_EN,s.BILLTYPE,s.BasicColor}).ToList();foreach (var rest in res)
{var tmpss = new ResBusinessType();tmpss.LegalUnitID = rest.Key.LegalUnitID;tmpss.TYPE_CD = rest.Key.TYPE_CD;tmpss.TYPE_NAME = rest.Key.TYPE_NAME;tmpss.TYPE_NAME_EN = rest.Key.TYPE_NAME_EN;tmpss.BILLTYPE = rest.Key.BILLTYPE;tmpss.BasicColor = rest.Key.BasicColor;tmpss.OrgGUID = string.Join(",", rest.Select(c => c.OrgGUID));resultValue.Add(tmpss);
}var result = new List<TravelStandardList>();
if (ret != null)
{if (ret.travelStandards.Count > 0){var GroupModel = ret.travelStandards.GroupBy(s => new { s.PostLevel }).ToList();foreach (var item in GroupModel){var resultValue = new TravelStandardList();resultValue.travelStandards = new List<TravelStandardModel>();var TravelStandard = new TravelStandardModel();resultValue.PostLevel = item.Key.PostLevel;TravelStandard.PostLevel = item.Key.PostLevel;TravelStandard.HotelExpenseStandard = item.Where(s => s.HotelExpenseStandard != null).Select(s => s.HotelExpenseStandard).FirstOrDefault();TravelStandard.TrafficExpenseStandard = item.Where(s => s.TrafficExpenseStandard != null).Select(s => s.TrafficExpenseStandard).FirstOrDefault();TravelStandard.IsOverSeas = item.Select(s => s.IsOverSeas).FirstOrDefault();resultValue.travelStandards.Add(TravelStandard);result.Add(resultValue);}}}var EmployeeGroup = trips.GroupBy(s => s.EmployeeID).ToList();foreach (IGrouping<string, TripEmployeeModel> item in EmployeeGroup){foreach (var items in item){}}var EmployeeGroup = trips.GroupBy(s => s.EmployeeID).Where(s=>s.Count()>1).ToList();//獲取重復(fù)項
轉(zhuǎn)載于:https://www.cnblogs.com/imtudou/p/11251636.html
總結(jié)
以上是生活随笔為你收集整理的从List分组后重新组织数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图像的掩膜操作
- 下一篇: Substring() 截取