码迷,mamicode.com
首页 > 其他好文 > 详细

从List分组后重新组织数据

时间:2019-07-26 17:32:51      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:group   col   ips   mode   icc   type   组织   var   standard   

///从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分组后重新组织数据

标签:group   col   ips   mode   icc   type   组织   var   standard   

原文地址:https://www.cnblogs.com/imtudou/p/11251636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!