private decimal GetBankAccountCashierTotal()
{
var company = _context.Company.FirstOrDefault();
return _context.PersonBankAgencyAccount
.Where(p => p.PersonID.Equals(company.PersonID))
.Where(c => c.BankAgencyAccountBalance
.Any(b => b.Reference <= DateTime.Now))
.Select(x => x.BankAgencyAccountBalance
.Where(d => d.Reference.Date <= DateTime.Now)
.OrderByDescending(d => d.Reference)
.FirstOrDefault()
.CurrentBalance)
.sum();
}
This is my complete method, in calling this method I have an exception
"An exception of type 'System.Data.SqlClient.SqlException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code "
and in the output
"Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler: Error: An exception occurred in the database while iterating the results of a query. System.Data.SqlClient.SqlException: Can not perform an aggregate function on an expression containing an aggregate or a subquery. "