Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 views
in Technique[技术] by (71.8m points)

entity framework 4 - SQL Table Paging PERFORMANCE ...is EF4 + Linq SKIP +TAKE equal in performance than using TSQL params to request "paging" on a SQL Table?

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 and Skip() and Take() procedure to request paging ....or is it better to do it on a GetList() Stored Procedure itself?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...