1
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 the call of 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: Cannot perform an Aggregate Function on an Expression containing an Aggregate or a subquery."
What’s the bug? You probably need to see what comes before in the code to see what’s missing.
– Maniero