我必须在我的程序中每一张账单显示一行,但一张账单有超过 1 个子账单。我想将来自 2 个表的信息分组到一个 DataGridView 中。1 行必须显示有关所有子帐单的分组信息。只有 2 列比其他列更复杂:“描述”和“总和”。“描述”必须包含所有子票据的描述,并用换行符分隔。我做了下一个方法:
var documentQuery = (from doc in entities.Bas_DocumentData
select new
{
DocumentNum = doc.DocumentNum,
DocumentDate = doc.DocumentDate,
Description = doc.Bas_BonusData.Select(t => t.Description),
BillsCount = doc.Bas_BonusData.Count,
SupplierNum = doc.Bas_BonusData.Select(cred => cred.SupplierNum).FirstOrDefault(),
Debitor = doc.Bas_BonusData.Select(deb => deb.DebitorNum).FirstOrDefault(),
Manager = doc.Bas_BonusData.Select(manager => manager.ManagerName).FirstOrDefault(),
SupplierName = doc.Bas_BonusData.Select(supp => supp.SupplierName).FirstOrDefault(),
Sum = doc.Bas_BonusData.Sum(bill => bill.Price),
IsPrinted = doc.isPrinted,
IsSent = doc.isSent,
NotSummarize = doc.NotSummarize
}).OrderBy(key => key.DocumentNum)
.ToList()
.Select(q => new AcceptedBonusProjection
{
DocumentNum = q.DocumentNum,
DocumentDate = q.DocumentDate,
Description = String.Join("\n\r", q.Description.ToArray()),
BillsCount = q.BillsCount,
SupplierNum = q.SupplierNum,
Debitor = q.Debitor,
Manager = q.Manager,
SupplierName = q.SupplierName,
Sum = q.Sum,
IsPrinted = q.IsPrinted,
IsSent = q.IsSent,
NotSummarize = q.NotSummarize
});
有没有更好的方法来实现我的目标?我可以通过哪种方式缩短此查询?