SQL Table Paging PERFORMANCE …is EF4 + Linq SKIP +TAKE equal in performance than using TSQL params to request “paging” on a SQL Table?

前端 未结 1 511
广开言路
广开言路 2020-12-17 22:39

If I want to retrieve records from 20 to 39, or from 40 to 59 from an MSSQL Table.

Since I\'m using MVC and EF4, is performance the same if I just do a Linq query a

相关标签:
1条回答
  • 2020-12-17 23:18

    If you execute this linq query:

    var data = context.Posts.OrderBy(p => p.Id).Skip(20).Take(20).ToList();
    

    It will produce this SQL:

    SELECT TOP (20) 
      [Extent1].[Id] AS [Id], 
      [Extent1].[Text] AS [Text]
    FROM ( SELECT 
             [Extent1].[Id] AS [Id], 
             [Extent1].[Text] AS [Text], 
             row_number() OVER (ORDER BY [Extent1].[Id] ASC) AS [row_number]
        FROM [dbo].[Posts] AS [Extent1]
    )  AS [Extent1]
    WHERE [Extent1].[row_number] > 20
    ORDER BY [Extent1].[Id] ASC
    

    It is not such nice like custom SQL you would write in your stored procedure but in the meaning of performance it is the same. Pagining is done on database.

    0 讨论(0)
提交回复
热议问题