LINQ to SQL does not generate ORDER BY when DISTINCT is used?
The following basic LINQ to SQL statement does not result in the orderby working. As you can see in the T-SQL there is no orderby. Do you know why? LINQ to SQL: var results = (from stats in db.t_harvest_statistics orderby stats.unit_number select stats.unit_number).Distinct().ToList(); Above Results in following TSQL SELECT [Distinct1].[unit_number] AS [unit_number] FROM ( SELECT DISTINCT [Extent1].[unit_number] AS [unit_number] FROM [dbo].[t_harvest_statistics] AS [Extent1] ) AS [Distinct1] That is a limitation of SQL and Relational Algebra of where the ORDER BY is in relation to the DISTINCT