Code: Select all
((IEnumerable<dynamic>)order.SalesContract?.EarnestMoney.Deposits)?.Sum(x => (decimal)x.Amount - (decimal)x.AmountReturnedToBuyer) ?? 0;
"Index was out of range. Must be non-negative and less than the size of the collection."
or "Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type."
What is the correct and reliable way to sum the difference between the kept and returned amount for all earnest money deposits on an order?