Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

62 ms

Page Size

25

Current Page

584 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 584 Results Showing 14576 - 14600 of 24441

ID Name Category Price Stock Rating Reviews SKU
15135 Bulk Product 874dd9e7 Toys & Games $83.90 62 1.7 24 BULK-be9464bd
15136 Bulk Product f29add0c Clothing $954.54 334 4.9 48 BULK-53da098c
15137 Bulk Product 33fad57b Clothing $818.55 289 2.4 26 BULK-579399f0
15138 Bulk Product 1a6c223e Clothing $316.31 458 3.7 62 BULK-88349faf
15139 Bulk Product 88f132da Books $736.88 137 2.9 69 BULK-128b3cee
15140 Bulk Product ee7f27b1 Toys & Games $171.19 491 4.7 80 BULK-a8aa7ebd
15141 Bulk Product af5a28f9 Books $131.04 468 0.3 36 BULK-3c14913d
15142 Bulk Product c13e95da Sports & Outdoors $750.30 77 0.2 4 BULK-8643706c
15143 Bulk Product dd927be7 Electronics $474.74 210 1.7 55 BULK-2a405c42
15144 Bulk Product 0de849c6 Books $377.56 44 0.7 47 BULK-b17acc65
15145 Bulk Product 5794800d Toys & Games $337.10 155 1.0 16 BULK-bd2bf274
15146 Bulk Product c8c96b54 Electronics $348.86 234 2.5 16 BULK-6277a37a
15147 Bulk Product 3f6dfd47 Sports & Outdoors $193.54 469 4.6 12 BULK-85123bcc
15148 Bulk Product 08a0d8cd Books $10.70 98 4.9 65 BULK-db89f32d
15149 Bulk Product ceb2aaf1 Home & Garden $771.61 12 2.3 51 BULK-b1512d93
15150 Bulk Product 93f496ea Electronics $558.71 67 0.4 53 BULK-c4253144
15151 Bulk Product b5966fb2 Books $808.69 136 2.3 85 BULK-c1397648
15152 Bulk Product 9f3b752a Sports & Outdoors $347.78 114 0.7 4 BULK-ef867c55
15153 Bulk Product fb7a282e Toys & Games $627.30 427 4.8 88 BULK-299ef746
15154 Bulk Product 5338a822 Toys & Games $28.05 77 3.4 99 BULK-e1c274dc
15155 Bulk Product 80e15587 Books $499.89 405 4.8 72 BULK-4a9bbd96
15156 Bulk Product 9c5ce28a Electronics $697.10 390 3.5 73 BULK-da450206
15157 Bulk Product 1fdfec72 Books $594.27 107 2.0 15 BULK-43c0edaa
15158 Bulk Product 0103fa59 Clothing $196.79 444 0.3 8 BULK-8c90ef24
15159 Bulk Product d0c1bbe3 Clothing $716.05 303 0.6 13 BULK-00ee278a
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