Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

61 ms

Page Size

25

Current Page

362 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 362 Results Showing 9026 - 9050 of 24441

ID Name Category Price Stock Rating Reviews SKU
9585 Bulk Product 92d6b03d Toys & Games $497.13 484 0.1 48 BULK-14e4b13f
9586 Bulk Product 6dbc8126 Home & Garden $293.90 45 1.1 95 BULK-49d7b2ae
9587 Bulk Product 3c6406ba Books $849.13 13 4.2 75 BULK-e7f14cd7
9588 Bulk Product 135e596f Books $401.84 498 2.7 90 BULK-ba655fef
9589 Bulk Product 47e6b6d4 Toys & Games $497.83 197 3.5 9 BULK-7ca66455
9590 Bulk Product 0cdd786f Sports & Outdoors $819.06 53 4.5 1 BULK-83b07519
9591 Bulk Product 201b8d11 Toys & Games $407.96 262 3.0 55 BULK-f672c458
9592 Bulk Product 8d90f09c Toys & Games $12.36 294 1.2 1 BULK-8e317b71
9593 Bulk Product ad8801fc Toys & Games $65.52 242 2.4 79 BULK-77b737e7
9594 Bulk Product 6379c14b Clothing $234.34 337 1.4 20 BULK-f2581b93
9595 Bulk Product 68577486 Home & Garden $103.43 479 4.2 49 BULK-e24e4d67
9596 Bulk Product 314a7a89 Books $782.30 436 1.1 14 BULK-c4cd1619
9597 Bulk Product bc69f32a Toys & Games $867.41 69 2.2 72 BULK-5e5dba81
9598 Bulk Product 62abbc47 Electronics $961.10 216 0.8 61 BULK-945ee2f1
9599 Bulk Product 231f5b4a Home & Garden $69.29 110 2.4 47 BULK-bf0a1a57
9600 Bulk Product 0b8cfada Home & Garden $74.98 247 2.8 52 BULK-f9d4e1d5
9601 Bulk Product 4952d6d8 Sports & Outdoors $158.54 315 0.2 55 BULK-264376be
9602 Bulk Product 25c0fba4 Clothing $383.81 151 1.5 56 BULK-b5bb59c8
9603 Bulk Product 92c51f38 Books $853.92 122 3.4 90 BULK-b34fb880
9604 Bulk Product 591863a7 Sports & Outdoors $1,001.73 142 1.2 97 BULK-150a0e09
9605 Bulk Product 168654de Toys & Games $389.26 309 2.7 15 BULK-db49c709
9606 Bulk Product eebd2b84 Home & Garden $230.96 375 3.0 11 BULK-df1c205c
9607 Bulk Product 23611b0f Home & Garden $996.08 430 2.8 96 BULK-9052e90c
9608 Bulk Product c262a19f Toys & Games $170.50 105 4.8 25 BULK-4d882ccc
9609 Bulk Product fc577c3e Clothing $924.00 488 0.5 6 BULK-bb8ad75c
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