Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

797 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 797 Results Showing 19901 - 19925 of 24441

ID Name Category Price Stock Rating Reviews SKU
20460 Bulk Product ab004cb0 Toys & Games $546.04 242 2.1 12 BULK-5d6461bb
20461 Bulk Product b4f95700 Toys & Games $554.77 78 4.3 87 BULK-02373b1c
20462 Bulk Product 8921034c Clothing $983.56 25 3.9 10 BULK-62a10a51
20463 Bulk Product 0350aace Clothing $151.44 93 2.5 53 BULK-073d52c8
20464 Bulk Product a081dd3c Sports & Outdoors $239.49 284 1.8 49 BULK-ca8b8d47
20465 Bulk Product 2d187a36 Electronics $826.72 11 1.9 52 BULK-8b13b7c8
20466 Bulk Product 70b3d6d8 Clothing $461.55 409 3.4 87 BULK-6d831bc2
20467 Bulk Product 1da7442a Clothing $523.08 19 3.2 50 BULK-3a2f799c
20468 Bulk Product ca242ea7 Books $863.19 490 4.5 36 BULK-6e3620ab
20469 Bulk Product da93eb9a Toys & Games $752.62 134 1.7 65 BULK-558799be
20470 Bulk Product 14a9c6a6 Clothing $964.47 16 1.2 66 BULK-6ae2b2e4
20471 Bulk Product 54929858 Clothing $230.70 333 4.0 97 BULK-6b05b291
20472 Bulk Product 5055cd55 Toys & Games $818.39 32 3.9 14 BULK-4bb59ec7
20473 Bulk Product 8cb92208 Home & Garden $96.67 332 2.8 61 BULK-425b2a9e
20474 Bulk Product 73531cdf Clothing $598.62 137 1.0 83 BULK-3e0e60d8
20475 Bulk Product d52dbedb Toys & Games $250.01 199 4.7 62 BULK-118dcc8e
20476 Bulk Product 1e15d96f Toys & Games $479.53 254 3.4 65 BULK-81c832b5
20477 Bulk Product 48d7e176 Clothing $426.44 396 2.2 19 BULK-6b78e465
20478 Bulk Product d5544782 Home & Garden $215.20 289 0.2 65 BULK-a986965d
20479 Bulk Product 42672996 Home & Garden $139.70 362 1.0 72 BULK-63852fde
20480 Bulk Product f62e13da Sports & Outdoors $640.91 407 3.0 82 BULK-8ddee902
20481 Bulk Product 8a58ffe5 Sports & Outdoors $705.13 487 4.5 23 BULK-cd1a65cd
20482 Bulk Product 06ab6e57 Clothing $577.46 319 1.4 52 BULK-abe267e0
20483 Bulk Product 873e6b54 Sports & Outdoors $538.22 130 2.3 13 BULK-f88079ad
20484 Bulk Product 4af0e173 Sports & Outdoors $135.11 24 3.5 57 BULK-976fe57a
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