我有一个Invoice类,我想拥有多个软件包,但是我只希望那些软件包的发货时间比Record中的最后一条记录晚。我一直在使用“ 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

最佳答案

您可以将它们分别更改为两个查询,然后满足第二个条件(可能首先调用第二个条件,以便可以为where创建变量)。下面的文章向您展示了如何在select语句中执行此操作。

This would also solve your problem

08-17 22:54