This has probably been asked before, but I am struggling to find an answer. I have the below code, trying to get a running total.
This is not an error that I have seen before and stumped as to what it actually means, or how to fix it, and trying to keep this in one query if possible. However, will be open to better ways to do this.
I have added a comment where the error is occurring and what the error is inside Visual Studio.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
class VMAccountWindow : BaseViewModel
{
public VMAccount()
{
using (DBContext db = new DBContext())
{
decimal currentTotal = 0;
var tl = db.Transaction
.OrderByDescending(
p => p.TransactionDate
)
.Select(p => new TransactionList
{
AccountId = p.AccountId,
TransactionDate = p.TransactionDate,
Deposit = p.TransCode == "Deposit" ? p.TransactionAmount.ToString() : "",
Withdrawal = p.TransCode == "Deposit" ? "" : p.TransactionAmount.ToString(),
Notes = p.Notes,
// Following gives an error about Expression tree may not contain an assignment operator
AccountBalance = currentTotal += p.TransCode == "Deposit" ? p.TransactionAmount : -p.TransactionAmount
})
.Where(o => o.AccountId == 1)
.ToList();
}
}
}
public class TransactionList
{
public int AccountId { get; set; }
public string TransactionDate { get; set; }
public string Deposit { get; set; }
public string Withdrawal { get; set; }
public string Notes { get; set; }
public decimal AccountBalance { get; set; }
}
Any help would be appreciated.