I have an MVC app using Linq to Entities and I’m having a hard time figuring out how to get this part of a query written. This is an excerpt from a SQL Stored Procedure that works. I know I can use the procedure but I’m trying to get a better understanding of LINQ. The goal is to get the last Routing for a requisition and the ReqRoutingID is an identity filed so the last entry in the table is always the one I want.
SELECT
h.ReqID,
rr.RoutingSectionID
FROM LOG_ReqHeader h
JOIN dbo.Log_ReqRoutings rr
ON rr.ReqRoutingID = (
SELECT TOP 1 r.ReqRoutingID
FROM Log_ReqRoutings r1
WHERE r1.ReqID = h.ReqID
ORDER BY r1.ReqRoutingID desc)
1 Answer