我有一个 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)
这个查询可以工作,除非如果有多个包裹,我会得到多张相同的发票。如果我在加入的末尾添加“到包中”,我不知道如何只获取满足第二个条件的包。
子查询是:
(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