我有以下方法可以进行一些分组
private List<CatalogVehicle> GroupResult(IEnumerable<VehicleAndQuote> vehiclesAndQuotes)
{
var vehicles = vehiclesAndQuotes
.GroupBy(vehicleAndQuote =>
new
{
vehicleAndQuote.Vehicle.VehicleMakeName,
vehicleAndQuote.Vehicle.VehicleModelTypeName,
vehicleAndQuote.Vehicle.VehicleEdition
})
.Select(a => new
{
vehicle = _mapper.Map<VehicleAndQuote, CatalogVehicle>(a.First()),
plans = GetLeasingpPlansGroupedByYearlyMileages(a.ToList()) //<== this one is taking ages
})
.Select(a =>
{
a.vehicle.LeasingPlans = a.plans;
return a.vehicle;
});
return vehicles.ToList();
}
以及在其中调用的方法;
private List<LeasingPlan> GetLeasingpPlansGroupedByYearlyMileages(IEnumerable<VehicleAndQuote> vehicleAndQuotes)
{
return vehicleAndQuotes.GroupBy(quote => quote.Quote.YearlyMileage)
.Select(group => _mapper.Map<List<VehicleAndQuote>, LeasingPlan>(group.ToList()))
.ToList();
}
最后一种方法需要很长时间。在IEnumerable<VehicleAndQuote> vehiclesAndQuotes约30.000的记录。有没有我没有看到的性能提升器?
慕村225694
四季花海
相关分类