複数のパッケージが必要な Invoice クラスがありますが、レコードの最後のレコードよりも後に出荷された場合にのみ、それらのパッケージが存在するようにします。他のグループをオブジェクトに入れるために「into」を使用してきましたが、特定のパッケージだけを結合するのに苦労しています。
from invoice in invoices
join item in InvoiceItems on invoice.InvoiceId equals item.InvoiceId into items // Gives the item collection
join package in packages on invoice.InvoiceId equals package.InvoiceId // only want the packages that satisfy the condition...
where package.ShipDate > (subquery)
複数のパッケージがある場合に同じ請求書を複数取得することを除けば、このクエリは機能します。結合の最後に「パッケージに」を追加すると、2 番目の条件を満たすパッケージのみを取得する方法がわかりません。
サブクエリは次のとおりです。
(from lastSentRecord in records
where lastSentRecord.InvoiceID == invoice.InvoiceID
orderby lastSentRecord.SendDateTime descending
select lastSentRecord.SendDateTime ?? new DateTime()).First()
クラス構造の重要な部分は、
Invoice --- InvoiceID
Package --- InvoiceID, ShipDate
Record --- InvoiceID, SendDateTime, EmailType