linq 分组
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) };
生活没有输赢,不要在乎别人如何评价你,开心就好。
QQ群:158138959