Entity Framework/Linq to SQL: Skip & Take

后端 未结 6 2390
一个人的身影
一个人的身影 2020-11-27 15:19

Just curious as to how Skip & Take are supposed to work. I\'m getting the results I want to see on the client side, but when I hook up the AnjLab SQL Profiler and look a

6条回答
  •  有刺的猬
    2020-11-27 15:23

    If you are using SQL Server as DB

    Then you can convert

    context.Users.OrderBy(u => u.Id)
    .Skip(() => 10)
    .Take(() => 5)
    .ToList
    

    =>

    SELECT 
    [Extent1].[Id] AS [Id], 
    [Extent1].[UserName] AS [UserName]
    FROM [dbo].[AspNetUsers] AS [Extent1]
    ORDER BY [Extent1].[Id] ASC
    OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY
    

    refrence: https://anthonychu.ca/post/entity-framework-parameterize-skip-take-queries-sql/

提交回复
热议问题