0

Hi I can make this query no prob in sql, but having trouble making it in Linq. can someone please recreate the folling in Linq for me?

SELECT
   p.[Id]
  ,p.[SupplierId]
  ,p.[SupplierStatusId]
  ,p.[AircraftId]
  ,x.[Status]

FROM

(SELECT
    a.PlanId,
    a.CreatedDate,
    s.Name AS [Status]

FROM
(SELECT 
    PlanId, 
    MAX(CreatedDate) AS CreatedDate
FROM PlanStatus
GROUP BY PlanId) a 

LEFT JOIN PlanStatus ps ON a.PlanId = ps.PlanId AND a.CreatedDate = ps.CreatedDate 
LEFT JOIN Status s ON ps.StatusId = s.Id
) x

LEFT JOIN Plans p ON x.PlanId = p.Id
BobbyB
  • 121
  • 4
  • 12
  • Create a function in SQL and then add it to `DBML` and use it in `LINQ`. `Left joins` are very complex to describe in `LINQ` (in my point of view) – Bogdan Bogdanov Apr 27 '15 at 16:55
  • I don't think joins are that complex to describe in LINQ, but maybe you could first try it yourself and then show us how far you've come. [This discussion](http://stackoverflow.com/questions/3404975/left-outer-join-in-linq) can give you some ideas on how to approach LINQ join queries. – flaudre Apr 28 '15 at 10:35

0 Answers0