Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

51 ms

Page Size

25

Current Page

839 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 839 Results Showing 20951 - 20975 of 24441

ID Name Category Price Stock Rating Reviews SKU
21510 Bulk Product 53d0ea97 Sports & Outdoors $245.65 54 3.7 47 BULK-2e0c6281
21511 Bulk Product 5d899ea4 Clothing $152.25 206 3.1 2 BULK-4d84b830
21512 Bulk Product eff38c7f Clothing $937.16 182 4.6 2 BULK-41d74577
21513 Bulk Product 1c1fdc44 Clothing $72.35 61 1.6 75 BULK-16694b51
21514 Bulk Product b1b8b313 Sports & Outdoors $174.58 181 5.0 73 BULK-c51ed80a
21515 Bulk Product 4ee5d697 Home & Garden $583.78 266 4.5 16 BULK-fd0fbaf8
21516 Bulk Product 0c13dd50 Books $457.15 189 2.6 48 BULK-6f48548b
21517 Bulk Product 1c014480 Home & Garden $667.53 86 4.6 77 BULK-15747a71
21518 Bulk Product 1ba2b5ec Toys & Games $362.09 62 1.2 74 BULK-eea999bf
21519 Bulk Product b02dc82b Home & Garden $552.56 184 1.7 30 BULK-0881c12a
21520 Bulk Product a47e0b51 Electronics $232.95 309 3.8 24 BULK-a2c4f69e
21521 Bulk Product eb170f0e Home & Garden $264.91 351 0.0 67 BULK-036d058a
21522 Bulk Product 00cd40ab Clothing $488.86 480 3.7 53 BULK-0c200c36
21523 Bulk Product 9478d7a4 Sports & Outdoors $576.51 117 0.7 79 BULK-fca564e6
21524 Bulk Product a95b1943 Toys & Games $638.23 460 4.3 36 BULK-ecd551ac
21525 Bulk Product b982bc9e Clothing $20.63 434 3.0 0 BULK-5235c3eb
21526 Bulk Product 5e039197 Sports & Outdoors $669.25 25 1.0 43 BULK-cbe222f1
21527 Bulk Product 2b3d4e4e Sports & Outdoors $952.76 250 4.0 43 BULK-006a6f17
21528 Bulk Product a8797c71 Toys & Games $281.36 432 2.0 18 BULK-a0c50d4c
21529 Bulk Product ac18137a Home & Garden $841.45 103 0.5 84 BULK-773a1a97
21530 Bulk Product b0f43df3 Toys & Games $618.70 493 0.3 37 BULK-7f83c961
21531 Bulk Product 2580c7ca Electronics $432.00 420 0.4 2 BULK-6d509ec8
21532 Bulk Product 1fc4c4a2 Clothing $994.49 455 1.5 32 BULK-c1422fbf
21533 Bulk Product f7ca4ede Toys & Games $831.66 486 2.6 59 BULK-c5689e2c
21534 Bulk Product 7cbd5991 Sports & Outdoors $687.63 274 4.8 42 BULK-ce8d9279
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