我有一個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。我會將子查詢添加到問題 –