Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

883 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 883 Results Showing 22051 - 22075 of 24441

ID Name Category Price Stock Rating Reviews SKU
22610 Bulk Product 2c987b55 Clothing $404.24 256 4.1 98 BULK-1bbb2ede
22611 Bulk Product 574e8e46 Sports & Outdoors $176.89 251 2.1 93 BULK-f5b9c41c
22612 Bulk Product 5b8bd3d1 Electronics $583.64 83 3.6 48 BULK-603a637b
22613 Bulk Product 2c4e9da8 Sports & Outdoors $233.33 293 2.5 23 BULK-661cc044
22614 Bulk Product d1ec361e Books $152.83 392 4.6 31 BULK-51452312
22615 Bulk Product 14d07614 Clothing $716.68 218 0.4 80 BULK-8e13949e
22616 Bulk Product 8913bae9 Books $749.92 407 2.0 14 BULK-4691ff61
22617 Bulk Product 44e558d1 Toys & Games $845.89 485 5.0 46 BULK-260791f4
22618 Bulk Product c36a37e7 Clothing $363.90 29 4.2 2 BULK-2d23ebba
22619 Bulk Product 6a9ca0b5 Books $41.85 217 1.2 51 BULK-0eb60ba9
22620 Bulk Product 8eca20a5 Toys & Games $577.81 302 2.0 9 BULK-9d6c098d
22621 Bulk Product 95df5539 Clothing $207.62 319 4.7 92 BULK-d1cb20d1
22622 Bulk Product c495499c Home & Garden $630.91 467 0.4 1 BULK-b27522bd
22623 Bulk Product f26b622f Clothing $716.91 144 4.0 98 BULK-02cb1a82
22624 Bulk Product 73beec33 Home & Garden $923.95 61 3.9 54 BULK-054a02e1
22625 Bulk Product c651edd9 Electronics $114.74 391 2.9 52 BULK-2a2f2b87
22626 Bulk Product 16b3116f Books $519.33 311 1.3 26 BULK-ab4f2002
22627 Bulk Product 08f0cc9e Clothing $763.72 481 4.8 74 BULK-7c998eb3
22628 Bulk Product 9231b4cc Home & Garden $873.35 284 0.4 84 BULK-6c3c648b
22629 Bulk Product b46ce615 Books $675.64 409 3.4 29 BULK-a5fe3ece
22630 Bulk Product 66d61766 Electronics $987.38 314 3.2 66 BULK-e25454ba
22631 Bulk Product b581da28 Books $226.32 115 1.4 64 BULK-539307f3
22632 Bulk Product 6096e2c6 Electronics $77.73 468 0.4 41 BULK-b3bba3dc
22633 Bulk Product 1047c7ab Books $358.78 244 4.8 64 BULK-ab9df978
22634 Bulk Product 4ad15146 Electronics $15.36 376 2.9 68 BULK-e04812cd
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