Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

25

Current Page

938 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 938 Results Showing 23426 - 23450 of 24441

ID Name Category Price Stock Rating Reviews SKU
23985 Bulk Product 07d7f77e Sports & Outdoors $131.09 428 4.9 82 BULK-d0c6af80
23986 Bulk Product cdea1397 Toys & Games $957.83 228 0.0 41 BULK-d146de19
23987 Bulk Product 96a81da3 Books $924.90 295 3.6 96 BULK-82010fde
23988 Bulk Product 9d156292 Electronics $635.27 416 0.5 45 BULK-6d7f6d10
23989 Bulk Product c13f4cdb Home & Garden $487.89 388 1.5 91 BULK-2b1a2874
23990 Bulk Product 57a9868d Electronics $977.10 9 2.2 81 BULK-5c39694a
23991 Bulk Product cc41cb6e Sports & Outdoors $527.73 234 1.8 85 BULK-938db347
23992 Bulk Product bc7ce2a9 Sports & Outdoors $518.46 326 2.0 14 BULK-02425181
23993 Bulk Product 692e4b01 Electronics $825.90 477 3.5 2 BULK-1641f77d
23994 Bulk Product 00b65c9c Electronics $277.16 270 2.2 9 BULK-658b3e90
23995 Bulk Product db6fad2c Books $463.81 288 0.5 64 BULK-faffb77b
23996 Bulk Product bd5cdd88 Books $325.81 183 4.3 33 BULK-16aa8b35
23997 Bulk Product 2c403acd Books $635.84 108 1.6 6 BULK-2a4399db
23998 Bulk Product fa8564e6 Clothing $688.67 149 4.8 53 BULK-bcd4e5b2
23999 Bulk Product 58ec4788 Books $911.26 58 1.1 72 BULK-8c0fdc8f
24000 Bulk Product 72fa9451 Sports & Outdoors $238.21 15 3.2 61 BULK-fae4e0fc
24001 Bulk Product a9e0dcf8 Sports & Outdoors $516.00 355 3.2 35 BULK-611c1201
24002 Bulk Product dcdbfc62 Books $408.29 156 4.6 77 BULK-93c6a683
24003 Bulk Product 647175bc Clothing $161.04 260 1.8 11 BULK-295b9c9c
24004 Bulk Product 6b44ba4b Clothing $236.99 381 1.2 35 BULK-efe81aeb
24005 Bulk Product d123d4b9 Toys & Games $307.18 437 3.2 24 BULK-374adb4d
24006 Bulk Product 33c78120 Sports & Outdoors $308.66 485 0.1 92 BULK-8a0445ae
24007 Bulk Product af3a2d57 Home & Garden $425.79 358 2.8 42 BULK-d41a9fad
24008 Bulk Product 11a78251 Sports & Outdoors $86.59 374 3.6 22 BULK-ce3d8b6c
24009 Bulk Product 2d18102e Home & Garden $909.53 147 4.9 85 BULK-427b71b8
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