We are implementing some EF data repositories, and we have some queries which would include TOP 1
I have read many posts suggesting to use .Ta
From LINQPad:
C#:
age_Centers.Select(c => c.Id).First();
age_Centers.Select(c => c.Id).FirstOrDefault();
age_Centers.Select(c => c.Id).Take(1).Dump();
SQL:
SELECT TOP (1) [t0].[Id]
FROM [age_Centers] AS [t0]
GO
SELECT TOP (1) [t0].[Id]
FROM [age_Centers] AS [t0]
GO
SELECT TOP (1) [t0].[Id]
FROM [age_Centers] AS [t0]
*Note that Take(1)
enumerates and returns an IQueryable
.