I’m working on a simple financial application using MVVM & LinqToSql. I’m trying to find out the best way to structure my data. Here’s what I have (simplified):
Account
- AccountId (PK)
- AccountName
- AccountBalance (returns a sum on the transactions column)
- Transactions (EntitySet)
I’m working on displaying the list of transactions for a given account, and I’m running into some trouble. What I’d like to do is display the transactions grouped by their date. To do this, I’m using the LongListSelector control, which allows for grouping. The datasource for the control is the following:
var transByDate = from trans in App.ViewModel.AllTransactions
trans by trans.TransDate.ToString("d") into t
t.Key ascending
new Transaction<Transaction>(t.Key, t);
this.lls_transByDate.ItemsSource = transByDate;
This works, and I see my group titles with the date, with transaction data for that day underneath it.
What I’m having an issue with is displaying the daily balance in the header with each date. How can I structure my data so that the account balance is easily accessible by date, but can be updated (if the user goes 2 weeks back and makes a change to an existing transaction).
Edit What I’d like to see:
[10/2/2011 ————– $753.23]
Transaction 1 – Grocery – $30.00
[10/1/2011 ————– $723.23]
Bank – Vehicle – $400.00
Store – Grocery – $35.00
[09/31/2011 ————– $288.23]
etc
Within my
Transaction<T>class, I added another property calledTransAmount. So when the constructor is called from the code block above, here’s what it’s doing.Then I just bind my XAML to that property. Perhaps there is a cleaner way of doing this, but I think re-calculating the balance would be cleaner than storing the balance int he database.