Linq子查询加入

时间:2015-04-27 16:23:04

标签: sql .net linq-to-sql

您好我可以在sql中使这个查询没有问题,但在Linq中遇到麻烦。有人可以为我重新创建Linq中的人吗?

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

0 个答案:

没有答案