Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

293 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 293 Results Showing 7301 - 7325 of 24441

ID Name Category Price Stock Rating Reviews SKU
7860 Bulk Product c43975d3 Home & Garden $673.09 79 2.9 31 BULK-80951941
7861 Bulk Product ada9678d Sports & Outdoors $813.93 50 4.2 77 BULK-1766188d
7862 Bulk Product 970c7799 Clothing $109.18 209 2.5 7 BULK-a978f34d
7863 Bulk Product 3bc0af21 Toys & Games $464.60 19 1.1 37 BULK-92436803
7864 Bulk Product 0d2cc769 Toys & Games $866.70 179 0.7 13 BULK-dd3e9eff
7865 Bulk Product f4176a61 Sports & Outdoors $418.20 329 4.5 40 BULK-2541462d
7866 Bulk Product 90e8aa47 Sports & Outdoors $834.32 197 0.5 71 BULK-4e7a251b
7867 Bulk Product 30ff651c Electronics $357.92 464 3.3 81 BULK-381c0c03
7868 Bulk Product 0a701e35 Home & Garden $898.47 262 3.6 32 BULK-0b4bd565
7869 Bulk Product ad6b32dd Home & Garden $748.25 425 3.6 49 BULK-6ab82ba7
7870 Bulk Product 79e4aee1 Sports & Outdoors $771.92 179 2.8 62 BULK-67244f86
7871 Bulk Product c1c7209f Home & Garden $568.41 151 0.8 40 BULK-ef635835
7872 Bulk Product 0d54d1fd Toys & Games $69.43 429 2.2 97 BULK-1540e5b7
7873 Bulk Product 9ebc2bf1 Home & Garden $633.91 205 4.5 65 BULK-7a223528
7874 Bulk Product 1a962e90 Toys & Games $352.63 107 4.3 3 BULK-060ca4bb
7875 Bulk Product 47887c94 Clothing $321.25 71 1.9 77 BULK-922b62c9
7876 Bulk Product 9b95e6fb Home & Garden $326.12 367 0.0 29 BULK-c214592d
7877 Bulk Product 36d6dfc7 Electronics $517.91 388 2.1 68 BULK-72e31c73
7878 Bulk Product dc971e92 Books $391.86 292 1.7 94 BULK-a217a62c
7879 Bulk Product e4a3d651 Home & Garden $155.65 107 1.0 12 BULK-fda7f117
7880 Bulk Product 6e98aa6a Clothing $287.99 137 2.2 51 BULK-02bdc15e
7881 Bulk Product 71058ac2 Electronics $710.53 11 1.5 56 BULK-0efffa36
7882 Bulk Product 01c9493a Electronics $786.80 199 1.4 25 BULK-a3534371
7883 Bulk Product d881d226 Electronics $90.34 211 0.3 7 BULK-826f7b13
7884 Bulk Product 77748146 Home & Garden $773.62 97 3.5 17 BULK-670752d6
Implementation Code
// Efficient pagination with Skip and Take
public async Task<PaginatedResult<DemoProduct>> GetPaginatedProductsAsync(int page, int pageSize)
{
    // Get total count (cached if possible)
    var totalCount = await _context.DemoProducts.CountAsync(p => p.IsActive);
    
    // Get page of results
    var items = await _context.DemoProducts
        .Where(p => p.IsActive)
        .OrderBy(p => p.Id) // Important: Must have ORDER BY for consistent paging
        .Skip((page - 1) * pageSize) // OFFSET in SQL
        .Take(pageSize) // FETCH NEXT in SQL
        .AsNoTracking() // No tracking needed for read-only
        .ToListAsync();

    return new PaginatedResult<DemoProduct>
    {
        Items = items,
        TotalCount = totalCount,
        Page = page,
        PageSize = pageSize
    };
}
Pagination Best Practices
  • Always use OrderBy: Skip/Take require stable sorting for consistent results
  • Use AsNoTracking(): Pagination queries are typically read-only
  • Consider caching: Cache total count if dataset changes infrequently
  • Limit max page size: Prevent users from requesting too many records at once
  • Use indexed columns: Ensure ORDER BY columns are indexed for performance