我有以下代码:
var statements = db.statement
.OrderByDescending(d => d.id)
.Take(5)
.AsEnumerable()
.Select(d => new Statements
{
Accounts = d.statement_entry.AsEnumerable()
.GroupBy(b => b.currency)
.Select(b =>
new Account
{
In = b.Where(l => l.amount > 0).Sum(l => l.amount),
Out = b.Where(l => l.amount < 0).Sum(l => l.amount),
Balance = b.Sum(l => l.amount),
Currency = b.Key
}).OrderBy(b => b.Currency),
UploadedDate = d.uploaded_date,
Id = d.id
})
.ToList();
有没有办法我可以做到这一点AsEnumerable()
?据我了解,这AsEnumberable
将导致对每个statement
返回的 s 进行查询。
或者有没有更好的方法来重构代码?