我试图弄清楚如何使用 Linq 执行子选择。我有一个带有“借方”和“贷方”列的 Excel 表格。我需要过滤掉任何具有与进一步向下的贷方列值匹配的借方列值(> 0.00)的行。两行必须具有相同的付款人 ID。到目前为止,这是我想出的:
public void balanceSheet()
{
foreach (Payment payment in this.payments)
{
// c[6] is the payers ID.
var debits = from c in this.test.WorksheetNoHeader()
where c[6] != "0" && c[13] != "0.00"
select c;
// Find any rows in the sheet that have the same payer id AND the debit
// amount from the query above in it's credit column.
foreach(LinqToExcel.RowNoHeader debit in debits)
{
var credits = from c in this.test.WorksheetNoHeader()
where c[6] == debit[6] && c[15] == debit[13]
select c;
// Do something awesome if it finds something.
}
}
}
我希望有一种更优雅的解决方案来按上述标准选择 excel 行,而不是每次都循环遍历它们。我不认为我正在使用 LINQ 来发挥它的全部潜力。有任何想法吗?