您可以缩短以下记录吗?
我想直接在“选择”中获取总和
var res = (from PR in context.TblPremium
join P in context.TblPolicy.Where(p => p.ValidityTo == null) on PR.PolicyId equals P.PolicyId
join R in context.TblReporting on PR.ReportingCommissionID equals R.ReportingId
join O in context.TblOfficer on P.OfficerId equals O.OfficerId
where (PR.ReportingCommissionID != null
&& (PR.PayDate >= minDate && PR.PayDate <= maxDate)
&& PR.ValidityTo == null
&& O.Code == model.enrolment_officer_code)
select new
{
Commission = (R.CommissionRate == null ? 0.00M : R.CommissionRate) * PR.Amount,
PR.Amount
})
.ToList();
var c = res.AsEnumerable().Sum(x => x.Commission);
var a = res.AsEnumerable().Sum(x => x.Amount);
response = new { Commision = c, Amount = a };