我已按QueriedTransactionList
排序结果TTransactionID
,然后按BatchID
进行分组。出于某种原因,descending
的排序无效。它仍然按升序排序TTransactionID
。
QueriedTransactionList = db.Transactions.OrderByDescending(x => x.TTransactionID).GroupBy(x => x.BatchID).Select(x => x.FirstOrDefault()).ToList();
TransactionViewModel TransactionViewModel = new TransactionViewModel();
List<TransactionViewModel> TransactionDataList = QueriedTransactionList.Select(x => new TransactionViewModel
{
TTransactionID = x.TTransactionID,
BatchID = x.BatchID,
TransactionDateTime = x.TransactionDateTime,
TransactionStatus = x.TransactionStatus,
TaxPayerName = x.Card.TaxPayer.TaxPayerName,
TaxPayerEmail = x.Card.TaxPayer.TaxPayerEmail,
TaxPayerTIN = x.Card.TaxPayer.TaxPayerTIN,
DispatchBy = x.User.UserName,
DestinationPort = x.Card.Port.PortName,
BatchCards = Helper.GetBatchQtyByBatchID(x.BatchID)
}).ToList();