///从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();//获取重复项
原文地址:https://www.cnblogs.com/imtudou/p/11251636.html
时间: 2024-11-08 12:04:17