Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

1698 ms

Page Size

25

Current Page

209 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 209 Results Showing 5201 - 5225 of 24441

ID Name Category Price Stock Rating Reviews SKU
5760 Bulk Product ebf34d37 Electronics $937.56 332 3.6 18 BULK-9389f6be
5761 Bulk Product 71401e3b Electronics $35.16 463 2.5 39 BULK-3042a837
5762 Bulk Product 6aab2cbc Books $534.23 385 2.0 78 BULK-b6051eee
5763 Bulk Product 5a68be95 Home & Garden $277.12 161 0.7 1 BULK-67a46d33
5764 Bulk Product cc4ac898 Clothing $625.67 282 2.9 4 BULK-16a6b1a4
5765 Bulk Product e6dd8ba3 Sports & Outdoors $240.94 444 5.0 85 BULK-c7783295
5766 Bulk Product db0a3176 Sports & Outdoors $623.67 249 0.8 29 BULK-fbd53c3d
5767 Bulk Product f8184a55 Clothing $900.43 130 2.7 16 BULK-3c1ccfb0
5768 Bulk Product e3676036 Books $286.97 326 0.2 40 BULK-6843a48a
5769 Bulk Product 9cb4c013 Sports & Outdoors $157.08 365 4.8 38 BULK-28371cda
5770 Bulk Product 90c332c1 Electronics $910.54 229 0.6 90 BULK-cf652a6b
5771 Bulk Product 9c7432bd Electronics $426.61 159 2.4 92 BULK-975496cc
5772 Bulk Product 419d87c9 Sports & Outdoors $874.92 311 0.5 91 BULK-a2bc7ab6
5773 Bulk Product 9325103d Clothing $709.57 422 4.0 51 BULK-db79525c
5774 Bulk Product ba55a882 Sports & Outdoors $934.75 491 3.0 32 BULK-956b926d
5775 Bulk Product 5d492eed Electronics $880.83 280 2.2 67 BULK-7968b109
5776 Bulk Product 6a97dabd Books $282.72 48 4.7 18 BULK-50428469
5777 Bulk Product 42f69854 Electronics $730.33 429 0.2 40 BULK-dadf960b
5778 Bulk Product 722153cf Sports & Outdoors $742.30 135 3.5 96 BULK-7d4fe3f2
5779 Bulk Product 72d89874 Toys & Games $425.79 317 3.3 34 BULK-20ab58d9
5780 Bulk Product d54d4d00 Books $341.99 269 2.7 25 BULK-09a81da3
5781 Bulk Product 2c3e91f7 Books $270.25 350 2.4 14 BULK-0135453d
5782 Bulk Product 23f67e98 Electronics $185.58 94 4.5 78 BULK-e9f02881
5783 Bulk Product cac6f696 Clothing $373.36 49 2.8 4 BULK-a945e596
5784 Bulk Product 40791b06 Clothing $558.06 191 0.8 45 BULK-c8fdf9b7
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