Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

816 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 816 Results Showing 20376 - 20400 of 24441

ID Name Category Price Stock Rating Reviews SKU
20935 Bulk Product 4232818f Electronics $905.58 438 3.8 50 BULK-777b213e
20936 Bulk Product 915e9f40 Sports & Outdoors $425.95 145 4.9 71 BULK-d154577b
20937 Bulk Product 1d583db3 Sports & Outdoors $765.25 471 1.8 82 BULK-b621d3e2
20938 Bulk Product 2b05b987 Books $508.52 233 1.1 21 BULK-d73cd389
20939 Bulk Product 9cdee9cb Toys & Games $232.01 48 2.6 89 BULK-ca2c9871
20940 Bulk Product 43efb2ca Toys & Games $214.09 481 3.6 82 BULK-defc46b9
20941 Bulk Product 3b07c441 Electronics $16.31 246 3.8 97 BULK-2c3afffb
20942 Bulk Product 05044c14 Sports & Outdoors $135.28 287 0.6 34 BULK-608fb45b
20943 Bulk Product 9b51d442 Books $362.28 294 1.5 78 BULK-6f89a39a
20944 Bulk Product 0e474b2b Toys & Games $323.00 443 2.5 12 BULK-e27ea62c
20945 Bulk Product 23b3224c Home & Garden $772.48 213 3.7 23 BULK-0509bd93
20946 Bulk Product ad60f9f8 Sports & Outdoors $31.83 256 1.6 33 BULK-fa080ae0
20947 Bulk Product f92b871f Home & Garden $926.96 418 3.3 47 BULK-7bc8cee4
20948 Bulk Product 8d8eade7 Clothing $898.22 300 2.3 85 BULK-4aa60937
20949 Bulk Product 613e2891 Electronics $206.86 425 3.3 3 BULK-b36c15da
20950 Bulk Product 069ae64d Home & Garden $270.39 237 4.2 68 BULK-66ae8173
20951 Bulk Product a6eeea85 Books $14.89 16 4.3 27 BULK-92b8cf12
20952 Bulk Product 4dda58ab Clothing $143.38 147 2.0 48 BULK-f52aa415
20953 Bulk Product d08058ad Sports & Outdoors $198.87 87 4.7 7 BULK-31202d96
20954 Bulk Product b83b3116 Sports & Outdoors $908.32 459 1.6 78 BULK-279628a5
20955 Bulk Product aafbe499 Home & Garden $409.50 362 4.5 73 BULK-2d3d7e1c
20956 Bulk Product 1b559414 Home & Garden $547.01 69 4.8 5 BULK-1daf676c
20957 Bulk Product e4a2d9f5 Sports & Outdoors $920.74 343 1.0 84 BULK-5b56ee3b
20958 Bulk Product 1fb7f79c Home & Garden $393.35 129 2.0 2 BULK-94475913
20959 Bulk Product 7dfc3f33 Books $673.95 9 1.2 68 BULK-65b62ff7
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