c# - How to solve issue "Could not translate expression ...into SQL and could not treat it as a local expression." -
this question has answer here:
i have code below:
void main() { var q = in applicants where(a.claims.any()) select a.claims.sum(c => c.totalclaimamount()); q.dump(); } public static class myext { public static decimal totalclaimamount(this claim c) { var t = 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); return (decimal)t; } }
when run in linqpad below issue:
invalidoperationexception: not translate expression 'a.claims.sum(c => c.totalclaimamount())' sql , not treat local expression.
please me out. many thanks
there no corresponding command custom method in sql. compiler not translate expression. instead first items,then select results:
var items = applicants.where(a => a.claims.any()).tolist(); var results = items.select(a => a.claims.sum(c => c.totalclaimamount());
Comments
Post a Comment