从List分组后重新组织数据

Posted imtudou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从List分组后重新组织数据相关的知识,希望对你有一定的参考价值。

///从List分组后从重组织数据

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();//获取重复项

以上是关于从List分组后重新组织数据的主要内容,如果未能解决你的问题,请参考以下文章

java8 stream对数组按条件进行分组

将List进行分组后结果返回Map结果集

List分组后存入Dictionary

java后台对查询到的商品列表按店铺分组并返回json数据_新手学习

使用 Pandas 从多维数据中分组

精品list 元素 分组