查看下面的代码,我想按客户 ID 汇总/分组查询结果,其中客户 ID 列旁边的销售和收据列的总和。
var sales = from s in context.Sales
select new { id = s.CustomerID, sales = s.Amount, receipts = (decimal)0 };
var receipts = from r in context.Receipts
select new { id = r.CustomerID, sales = (decimal)0, receipts = r.Amount };
var summary = sales.Union(receipts).ToList();
我尝试使用以下组合来实现相同的目的:
var summary = sales.Union(receipts).GroupBy(e=>e.id).Select( ... )
……但无济于事。
期待获得正确的相关语法。