Get max & min from Entity Framework, in one query and with best query possible
I'm aware of this question, but what I would like to do is obtain something close to this generated SQL: select MAX(Column), MIN(Column) from Table WHERE Id = 1 When I try this: var query = from d in db.Table where d.Id == 1 select new { min = db.Table.Max(s => s.Column), max = db.Table.Min(s => s.Column) }; The generated sql looks like this: SELECT [Extent1].[Id] AS [Id], [GroupBy1].[A1] AS [C1], [GroupBy2].[A1] AS [C2] FROM [dbo].[Table] AS [Extent1] CROSS JOIN (SELECT MAX([Extent2].[Column]) AS [A1] FROM [dbo].[Table] AS [Extent2] ) AS [GroupBy1] CROSS JOIN (SELECT MIN([Extent3].[Column])