Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

858 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 858 Results Showing 21426 - 21450 of 24441

ID Name Category Price Stock Rating Reviews SKU
21985 Bulk Product 0eb5906d Books $144.22 454 0.6 95 BULK-964d4374
21986 Bulk Product f1b91703 Books $673.26 217 3.1 53 BULK-a7dcc395
21987 Bulk Product 117ecfee Home & Garden $669.17 34 5.0 86 BULK-5be0e4c0
21988 Bulk Product b069bf45 Clothing $803.47 49 3.5 18 BULK-56049953
21989 Bulk Product a4cea786 Electronics $925.38 419 3.2 42 BULK-aece211f
21990 Bulk Product dd441186 Books $130.33 438 1.1 79 BULK-988d1e04
21991 Bulk Product 753c9771 Toys & Games $174.11 96 2.5 46 BULK-3aa48e89
21992 Bulk Product 5e922a0c Sports & Outdoors $526.20 111 4.5 15 BULK-7ca0a6e1
21993 Bulk Product 197c3a58 Electronics $975.32 298 3.1 45 BULK-e612f18e
21994 Bulk Product 9e9929ae Books $108.93 90 1.9 49 BULK-b1ec7bae
21995 Bulk Product df15dd51 Electronics $217.05 64 3.7 9 BULK-5a7735e7
21996 Bulk Product 07371ff9 Books $418.19 409 1.2 17 BULK-9f263bd7
21997 Bulk Product dba00843 Toys & Games $406.56 147 1.7 72 BULK-214241b3
21998 Bulk Product cf88d48e Books $936.73 268 3.1 19 BULK-d4e1212c
21999 Bulk Product 8354678c Home & Garden $656.56 197 3.8 93 BULK-ac403370
22000 Bulk Product 3fc92935 Electronics $214.74 18 3.7 50 BULK-d89bf37b
22001 Bulk Product cba09824 Sports & Outdoors $668.92 41 3.2 74 BULK-c4c4b734
22002 Bulk Product aaf0e8af Home & Garden $219.97 363 0.1 53 BULK-b53c2d1a
22003 Bulk Product 1421ad09 Toys & Games $569.24 286 3.1 82 BULK-47996dd1
22004 Bulk Product 50a19c4e Sports & Outdoors $444.57 105 2.7 35 BULK-a01af17b
22005 Bulk Product 6b66c432 Sports & Outdoors $188.57 494 1.2 50 BULK-514ce2dd
22006 Bulk Product ea14c711 Clothing $280.61 378 1.1 13 BULK-ec03c086
22007 Bulk Product 5fa880e9 Sports & Outdoors $921.27 129 0.8 12 BULK-b0d5cae2
22008 Bulk Product 81083392 Sports & Outdoors $830.68 471 2.7 42 BULK-bade4dc3
22009 Bulk Product db3f7741 Clothing $742.83 390 0.2 18 BULK-76c748bc
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