目前无法使用实体框架进行测试,但常规 LINQ-to-SQL 允许以下语句:
var rpage1 = entities.GetSearchData(null,"en",null,true).Skip(0).Take(10)
var rpage2 = entities.GetSearchData(null,"en",null,true).Skip(10).Take(10)
var rlist = rpage1.ToList();
LINQ 将生成一个子句,如
WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1
在我的情况下,结果查询是(GetConstantsValues 是一个存储过程):
SELECT [t1].[value] AS [Value]
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY [t0].[value]) AS [ROW_NUMBER], [t0].[value]
FROM [dbo].[GetConstantsValues](@p0) AS [t0]
) AS [t1]
WHERE [t1].[ROW_NUMBER] BETWEEN @p1 + 1 AND @p1 + @p2
ORDER BY [t1].[ROW_NUMBER]
所以只有相关的结果被加载到程序中。
我认为,EF 应该与它相差不大。可能是错的。