我有这个sql查询是由linqpad生成的,它工作正常,但是我没有得到如何?
Linq语句
Documents.GroupBy(p => new { p.PatientId, p.DocumentType })
.Select(g => g.OrderByDescending(p =>
p.CreationDateTime).FirstOrDefault().DocumentId)
sql查询
SELECT (
SELECT [t3].[DocumentId]
FROM (
SELECT TOP (1) [t2].[DocumentId]
FROM [Document] AS [t2]
WHERE ([t1].[PatientId] = [t2].[PatientId]) AND ([t1].[DocumentType] = [t2].[DocumentType])
ORDER BY [t2].[CreationDateTime] DESC
) AS [t3]
) AS [value]
FROM (
SELECT [t0].[PatientId], [t0].[DocumentType]
FROM [Document] AS [t0]
GROUP BY [t0].[PatientId], [t0].[DocumentType]
) AS [t1]