Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

420 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 420 Results Showing 10476 - 10500 of 24441

ID Name Category Price Stock Rating Reviews SKU
11035 Bulk Product f8efbb4f Sports & Outdoors $684.16 344 1.9 32 BULK-03edaef8
11036 Bulk Product 39d13799 Home & Garden $264.42 410 4.4 14 BULK-be717994
11037 Bulk Product f9f85db4 Books $392.71 333 4.4 34 BULK-9b566488
11038 Bulk Product 0238ed0e Toys & Games $561.13 431 4.0 9 BULK-0c7b1a2f
11039 Bulk Product 18cc09f7 Toys & Games $724.45 378 0.7 75 BULK-01ec488f
11040 Bulk Product 1c0d6f10 Clothing $176.89 480 1.1 77 BULK-2cf7dd5c
11041 Bulk Product f5dd31e6 Clothing $681.52 429 1.2 44 BULK-d576a0ac
11042 Bulk Product b2128dd5 Electronics $201.80 23 2.1 26 BULK-07fc831c
11043 Bulk Product d42f56fa Clothing $827.75 183 1.5 49 BULK-ce9de674
11044 Bulk Product 0b998bea Books $32.30 76 1.4 72 BULK-2f5de248
11045 Bulk Product bb443b59 Sports & Outdoors $163.03 492 0.7 9 BULK-7e2d08d4
11046 Bulk Product dd8955ee Home & Garden $296.05 393 3.5 46 BULK-a817dc3d
11047 Bulk Product 1e2f188a Home & Garden $443.99 308 4.9 17 BULK-67c87d10
11048 Bulk Product 812b7a7b Home & Garden $81.56 280 4.0 66 BULK-e0afaf89
11049 Bulk Product 0a04afff Clothing $532.29 21 1.4 57 BULK-a2365578
11050 Bulk Product 2d25ed78 Toys & Games $748.11 107 3.1 70 BULK-5b9ac33c
11051 Bulk Product 24eb0bd9 Home & Garden $229.61 496 0.6 43 BULK-b2af967f
11052 Bulk Product 96da8714 Sports & Outdoors $64.97 33 1.2 59 BULK-459169e4
11053 Bulk Product e85aec9c Books $722.93 408 3.2 37 BULK-e5ed0afa
11054 Bulk Product d20361aa Toys & Games $168.89 26 2.4 47 BULK-a23e5a57
11055 Bulk Product ae449795 Toys & Games $864.75 307 0.1 55 BULK-d3347787
11056 Bulk Product 58cbb1b1 Toys & Games $625.41 8 2.4 10 BULK-e8340f29
11057 Bulk Product 53c79ed8 Clothing $958.39 363 3.8 62 BULK-c6b1f6cf
11058 Bulk Product abe885a2 Toys & Games $794.81 93 4.2 66 BULK-6afaf485
11059 Bulk Product bafda3dd Clothing $907.64 154 2.7 53 BULK-e7a4aa8c
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