我正在尝试对一些数据进行分组,但运气不佳。
我有一个数据列表
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; }
}
我想对此进行一些分组,所以我创建了几个类,例如
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; }
}
所以我可以按 BusinessName 分组,这很简单
var data = from c in transactions
group c by c.BusinessName
into business
select new BusinessTransaction()
{
Name = business.Key,
};
现在如何按 TransactionDateTime.Date 对交易进行分组?我想向客户端发回一个数据结构,如
BusinessName
28-06-12
Transaction
Transaction
27-06-12
Transaction
BusinessName
28-06-12
Transaction