LINQ is unable to convert the TotalClaimAmount
method call to a SQL expression.
What you can do, is to extract the expression from the TotalClaimAmount
method and use it directly in the Sum
method call.
public static class MyExt {
public static Func<Claim, decimal> TotalClaimAmountFunc = c =>
c.Accommodations.Sum(a => a.AmountClaimed) +
c.MealAllowances.Sum(ma => ma.AmountClaimed) +
c.Meals.Sum(m => m.AmountClaimed) +
c.Mileages.Sum(mi => mi.AmountClaimed) +
c.Others.Sum(o => o.AmountClaimed) +
c.ParkingTransits.Sum(pt => pt.AmountClaimed) +
c.Travels.Sum(tr => tr.AmountClaimed);
public static decimal TotalClaimAmount(this Claim c) {
return TotalClaimAmountFunc(c);
}
}
void Main() {
var q = from a in Applicants
where(a.Claims.Any())
select a.Claims.Sum(MyExt.TotalClaimAmountFunc);
q.Dump();
}