我想分組一些數據沒有太多的運氣。LINQ組條件後跟日期組
我有數據列表
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
考慮更改 '名單交易{獲得;組; }' 至 'IEnumerable > Transactions {get;組; }' –
pnvn