我有一个Invoice类,我想要多个包,但我只希望这些包在它们的发货时间晚于Record中的最后一个记录。我一直在使用“进入”来将其他组放入对象中,但我只能加入特定的包。linq to sql“into”with select
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
“Record”进来了吗?特别是,这是否取决于“发票”? –
你能提供你的数据集的结构吗? – m4ngl3r
@JonSkeet该记录是通知我们需要发送电子邮件。它有InvoiceID,EmailType,SentDate。我会将子查询添加到问题 –