c# 使用Linq 表达式 对查询结果分组,保留价格最低的一条

 public AirQueryPriceCNRes AirQueryPriceCNByComprehensive(AirQueryPriceCNRes result)
        {
            #region 空运查价结果处理
            /*******************************************************************************
             **空运查价综合排序处理: 1)路线 相同2)起飞机场 相同3)目的机场 相同4)航司相同**
             *******************************************************************************/

            var groupItems = (from p in result.List
                              group p by new
                              {

                                  p.FlightCourse,
                                  p.StartAirPortCode3,
                                  p.AirCompanyCode2,
                                  p.DestAirPortCode3


                              }
                              into t
                              select new
                              {

                                  TotalFee = t.Min(x => x.TotalFee),
                                  t.Key,
                                  Count = t.Count()


                              }).Where(x => x.Count > 1).ToList();
            foreach (var item in groupItems)
            {
                var b = result.List.RemoveAll(x => x.FlightCourse == item.Key.FlightCourse && x.AirCompanyCode2 == item.Key.AirCompanyCode2 && x.StartAirPortCode3 == item.Key.StartAirPortCode3 && x.DestAirPortCode3 == item.Key.DestAirPortCode3 && x.TotalFee != item.TotalFee);

            }
            return result;
            #endregion


        }

  

原文地址:https://www.cnblogs.com/TallkingIsEasying/p/15162070.html