我有一个查询汇总和汇总大量数据,如下所示:
var anonType = from x in collection
let Cars = collection.Where(c=>c.Code == "Cars")
let Trucks = collection.Where(c=>c.Code == "Trucks")
select new {
Total = collection.Sum(v=>v.Amount),
CarValue = Cars.Sum(v=>v.Amout),
TruckValue = Trucks.Sum(v=>v.Amount),
CarCount = Cars.Count(),
TruckCount = Trucks.Count()
};
我发现我必须声明范围变量 x 真的很奇怪,特别是如果我不使用它。那么,我做错了什么还是我应该遵循不同的格式?