I am trying to group some data without much luck.
I have a list of data
public class TransactionsViewModel
{
public string BusinessName { get; set; }
public string Description { get; set; }
public int TransactionTypeId { get; set; }
public string TransactionType { get; set; }
[Display(Name = "Transaction Amount")]
public decimal TransactionAmount { get; set; }
[Display(Name = "Transaction Date")]
public DateTime TransactionDateTime { get; set; }
}
I am wanting to do some grouping on this so I created a couple of classes like
public class BusinessTransaction
{
public string Name { get; set; }
public List<Transaction> Transactions { get; set; }
}
public class Transaction
{
public decimal TransactionAmount { get; set; }
public string Description { get; set; }
public DateTime TransactionDate { get; set; }
public string TransactionType { get; set; }
}
So I can group by BusinessName that is simple
var data = from c in transactions
group c by c.BusinessName
into business
select new BusinessTransaction()
{
Name = business.Key,
};
How can I group transactions now by TransactionDateTime.Date? I am wanting to send back to the client a data structure like
BusinessName
28-06-12
Transaction
Transaction
27-06-12
Transaction
BusinessName
28-06-12
Transaction
I think you want something like:
EDIT: That’s all the structure you can support with your current
BusinessTransactionclass. If you wanted to support the grouping directly, you’d have to add another level of nesting in there.However, using the existing structure the client can always group things themselves: