Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

248 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 248 Results Showing 6176 - 6200 of 24441

ID Name Category Price Stock Rating Reviews SKU
6735 Bulk Product 045f003b Books $1,009.98 261 3.0 54 BULK-17430544
6736 Bulk Product eaba0e81 Clothing $291.80 467 3.9 32 BULK-9c3d0dbc
6737 Bulk Product 9b1b0a24 Books $305.49 340 2.9 91 BULK-7ef3ca6d
6738 Bulk Product 6bd3fd44 Sports & Outdoors $77.37 375 0.8 76 BULK-a2bf0b6e
6739 Bulk Product d34026c8 Toys & Games $489.02 235 0.8 88 BULK-469d632b
6740 Bulk Product 30dac662 Sports & Outdoors $60.11 123 0.2 76 BULK-5a346c09
6741 Bulk Product 87dd2b10 Clothing $125.83 48 3.8 82 BULK-85de9b24
6742 Bulk Product 72cd0692 Books $751.91 476 2.7 32 BULK-deec181c
6743 Bulk Product 1e02564f Home & Garden $485.53 171 0.3 23 BULK-7eb73708
6744 Bulk Product 74b0785c Clothing $774.10 143 3.7 36 BULK-9908d2ef
6745 Bulk Product cf7ffc9d Electronics $455.06 392 3.9 7 BULK-851eed65
6746 Bulk Product 0823c19f Toys & Games $848.05 307 3.4 8 BULK-5bd87236
6747 Bulk Product d97d2e88 Home & Garden $276.35 338 3.3 11 BULK-3d32a159
6748 Bulk Product 9f9d7111 Toys & Games $362.80 13 4.9 17 BULK-62bd9be0
6749 Bulk Product 04e7568e Sports & Outdoors $384.18 408 1.6 90 BULK-d0e1f5f3
6750 Bulk Product 2ba26028 Toys & Games $256.09 330 3.9 64 BULK-9967cad9
6751 Bulk Product c54bee7f Toys & Games $667.09 260 2.8 55 BULK-7a11631a
6752 Bulk Product 02f6512d Clothing $48.30 352 3.2 58 BULK-4c08866e
6753 Bulk Product 1493a00d Clothing $148.41 294 0.7 27 BULK-cbcf16aa
6754 Bulk Product 44f94879 Clothing $431.35 297 2.2 12 BULK-3bb9a74e
6755 Bulk Product 2343780e Clothing $817.66 445 1.7 27 BULK-090cb6c6
6756 Bulk Product 025db36c Electronics $674.98 435 2.8 55 BULK-0cabb0e7
6757 Bulk Product 097b06cc Clothing $658.20 435 4.2 89 BULK-a1a17df5
6758 Bulk Product 8e87b25a Home & Garden $520.60 195 2.5 29 BULK-35ca81c7
6759 Bulk Product f9db2f15 Sports & Outdoors $646.95 144 3.2 42 BULK-b95f2b92
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