When I execute:
var t = db.Table1.OrderBy(x => x.Name).ToList();
In the SQL profiler, this is translated SQL:
SELECT [Extent1].[ID] AS [ID], [Extent1].[Name] AS [Name] FROM [dbo].[Table1] AS [Extent1] ORDER BY [Extent1].[Name] ASC
It is right.
However, if I pass the OrderBy selector function:
Func<Table1, string> f = x => x.Name; var t = db.Table1.OrderBy(f).ToList();
Translated SQL:
SELECT [Extent1].[ID] AS [ID], [Extent1].[Name] AS [Name] FROM [dbo].[Table1] AS [Extent1]
The order is not fully translated.
What is the problem? They are one and the same lambda function, the only difference in the second case, it is first assigned to a variable.
Nan li
source share