У меня есть этот sql-запрос, сгенерированный linqpad, он работает нормально, но я не получаю как?
Заявление Linq
Documents.GroupBy(p => new { p.PatientId, p.DocumentType })
.Select(g => g.OrderByDescending(p =>
p.CreationDateTime).FirstOrDefault().DocumentId)
sql query
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]