Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

283 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 283 Results Showing 7051 - 7075 of 24441

ID Name Category Price Stock Rating Reviews SKU
7610 Bulk Product 473d1c14 Home & Garden $879.47 340 0.1 24 BULK-3d96015b
7611 Bulk Product 7e07067b Electronics $180.19 74 2.5 82 BULK-73b686cf
7612 Bulk Product 3ecf86d7 Sports & Outdoors $257.11 230 4.2 95 BULK-0aab77b1
7613 Bulk Product 9fe94320 Home & Garden $430.06 19 0.2 62 BULK-2dcc31f0
7614 Bulk Product 0473372d Toys & Games $964.95 172 2.9 42 BULK-f1c9a695
7615 Bulk Product 7b688ac1 Clothing $325.94 477 2.6 4 BULK-a941ccde
7616 Bulk Product 67422891 Toys & Games $114.73 319 2.4 53 BULK-6eb386b4
7617 Bulk Product 3d3a2172 Toys & Games $253.60 204 2.7 78 BULK-13c8ba99
7618 Bulk Product 679de075 Electronics $850.51 408 4.3 75 BULK-7b0e36a3
7619 Bulk Product 2de5793a Toys & Games $579.34 75 1.8 76 BULK-1b5f2239
7620 Bulk Product 25e13985 Home & Garden $189.42 335 0.1 2 BULK-96eaae70
7621 Bulk Product 678638fd Clothing $268.69 72 3.3 50 BULK-30e1cd51
7622 Bulk Product 0beeee7d Clothing $771.47 327 0.9 1 BULK-87358818
7623 Bulk Product 4e54117f Clothing $182.61 345 0.1 13 BULK-6c5a6f53
7624 Bulk Product bfd2f531 Home & Garden $582.62 173 0.4 79 BULK-f8dd7fde
7625 Bulk Product 97e814b0 Electronics $562.49 175 2.7 72 BULK-1f46b067
7626 Bulk Product 0df6efb7 Sports & Outdoors $122.44 258 0.7 27 BULK-b4fb53d5
7627 Bulk Product 0b48d0ae Sports & Outdoors $593.18 465 0.3 49 BULK-46ede605
7628 Bulk Product fef15001 Home & Garden $361.56 199 1.3 40 BULK-a4913c60
7629 Bulk Product f910f94b Sports & Outdoors $797.07 489 1.8 88 BULK-4feda463
7630 Bulk Product 0d6fa358 Clothing $284.17 442 2.3 55 BULK-59e4cf69
7631 Bulk Product 1efe3204 Sports & Outdoors $847.16 295 1.4 83 BULK-359ce007
7632 Bulk Product aa10394b Sports & Outdoors $105.42 109 0.5 94 BULK-0426a9bc
7633 Bulk Product 14351ef0 Sports & Outdoors $10.75 77 2.4 66 BULK-32a94a0f
7634 Bulk Product 1e1c1134 Sports & Outdoors $630.70 271 4.7 9 BULK-d5bc2211
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