親レコードの最新の履歴レコードを取得する SQL サブセレクト クエリがあります。
以下を LINQ に変換する際に問題が発生しています。
SELECT *
FROM ProductRequests INNER JOIN ProductRequestHistory
ON ProductRequests.ID = ProductRequestHistory.ProductRequestsID
AND ProductRequestHistory.ID = (SELECT TOP 1 ProductRequestHistory.ID
FROM ProductRequestHistory
WHERE ProductRequestHistory.ProductRequestsID = ProductRequestHistory.ID
ORDER BY ProductRequestHistory.DateCreated DESC)
これは私が試したものですが、コンパイルされません:
from productrequests in db.ProductRequests
join productrequesthistories in db.ProductRequestHistories
on new { productrequests.ID, Column1 = (Int32?)Convert.ToInt32(
((from productrequesthistories0 in db.ProductRequestHistories
where
productrequesthistories0.ProductRequestsID == productrequesthistories0.ID
orderby
productrequesthistories0.ID descending
select new {
productrequesthistories0.ID
}).Take(1).First().ID)) }
equals new { ID = (System.Int32?)productrequesthistories.ProductRequestsID, Column1 = productrequesthistories.ID }
select new {
productrequests.ID,
productrequests.ProductRequestNumber,
productrequests.ProjectID,
Column1 = productrequesthistories.ID,
productrequesthistories.Title,
productrequesthistories.Requester,
productrequesthistories.TFSNumber,
productrequesthistories.UseCase,
productrequesthistories.RequestType,
productrequesthistories.FunctionalModule,
productrequesthistories.Description,
productrequesthistories.Reason,
productrequesthistories.Priority,
productrequesthistories.Status,
productrequesthistories.Release,
productrequesthistories.Estimate,
productrequesthistories.Wags,
productrequesthistories.Confidence,
productrequesthistories.Notes,
productrequesthistories.RequirementStatus,
productrequesthistories.RequirementDoco,
productrequesthistories.AlphaRequired,
productrequesthistories.Sprint,
productrequesthistories.Created,
productrequesthistories.DateChanged,
productrequesthistories.Checksum,
productrequesthistories.ProductRequestsID
}