Llinq查询 Skip,Take生成的sql语句
static void Main() { DBDataContext ctx = new DBDataContext(); var q = (from t in ctx.Teacher select t).Skip(2).Take(4); foreach (var item in q) { Console.WriteLine("ID={0},Name={1}", item.ID, item.Name); } Console.WriteLine("Done"); Console.ReadKey(); }
用sql profiler 监视运行的sql语句如下:
exec sp_executesql N'SELECT [t1].[ID], [t1].[Name], [t1].[Pwd], [t1].[Birthday] FROM ( SELECT ROW_NUMBER() OVER (ORDER BY [t0].[ID], [t0].[Name], [t0].[Pwd], [t0].[Birthday]) AS [ROW_NUMBER], [t0].[ID], [t0].[Name], [t0].[Pwd], [t0].[Birthday] FROM [dbo].[T_Teacher] AS [t0] ) AS [t1] WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1 ORDER BY [t1].[ROW_NUMBER]',N'@p0 int,@p1 int',@p0=2,@p1=4