如果我要从MSsql表中检索20到39之间的记录,或从40到59.
因为我使用MVC和EF4,性能是一样的,如果我只是做一个Linq查询和Skip()和Take()过程来请求分页….或者更好的做一个GetList()存储过程本身?
解决方法
如果你执行这个linq查询:
var data = context.Posts.OrderBy(p => p.Id).Skip(20).Take(20).ToList();
它会产生这个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