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を最大限に活用しているとは決して思いません。何か案は?