var data = from r in listRecords group r by new { r.CampaignId, r.CityId, r.Gift_DistributorId, r.ProductGiftId, FirstQuantity = listRecords.Where(a => a.CampaignId == r.CampaignId && a.CityId == r.CityId && a.Gift_DistributorId == r.Gift_DistributorId && a.ProductGiftId == r.ProductGiftId).Sum(c => c.FirstQuantity), Premium = listRecords.Where(a => a.CampaignId == r.CampaignId && a.CityId == r.CityId && a.Gift_DistributorId == r.Gift_DistributorId && a.ProductGiftId == r.ProductGiftId).Sum(c => c.Premium) } into g select g.Key ;参考 http://stackoverflow.com/questions/5231845/c-sharp-linq-group-by-on-multiple-column //修改后 var data2 = from r in listRecords group r by new { r.CampaignId, r.CityId, r.Gift_DistributorId, r.ProductGiftId, } into g select new { g.Key.CampaignId, g.Key.CityId, g.Key.Gift_DistributorId, g.Key.ProductGiftId, FirstQuantity = g.Sum(a => a.FirstQuantity), Premium = g.Sum(a => a.Premium) };
时间: 2024-10-17 11:02:04