Asp核心2.2,EF核心,MSSQL
此查询
var result1 = await context.Messages.OrderBy(cc=>cc.Id).LastOrDefaultAsync();
按预期生成SQL查询:
SELECT TOP(1) [cc].[Id], {other fields}
FROM [Messages] AS [cc]
ORDER BY [cc].[Id] DESC
和该查询
await context.Messages.LastOrDefaultAsync()
进行非常糟糕的SQL查询并迭代所有表:
SELECT [m].[Id], {other fields}
FROM [Messages] AS [m]
SQL事件探查器:
为什么?