Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

31 ms

Page Size

25

Current Page

716 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 716 Results Showing 17876 - 17900 of 24441

ID Name Category Price Stock Rating Reviews SKU
18435 Bulk Product b93b057a Toys & Games $983.70 391 3.7 43 BULK-e89d76c3
18436 Bulk Product ef626d8b Books $233.96 246 4.7 42 BULK-4d235e76
18437 Bulk Product d4314c9a Toys & Games $306.60 119 1.2 33 BULK-b525c616
18438 Bulk Product 3d8b6789 Sports & Outdoors $688.24 163 1.7 55 BULK-cbdc1159
18439 Bulk Product 9d2ab942 Home & Garden $294.73 84 2.7 9 BULK-751aa76e
18440 Bulk Product 54a4946e Books $968.25 254 2.1 7 BULK-174878f0
18441 Bulk Product d333c65f Sports & Outdoors $672.65 285 1.6 82 BULK-e0dac0e0
18442 Bulk Product cc737458 Toys & Games $800.08 336 0.7 42 BULK-15e93511
18443 Bulk Product f93f0694 Home & Garden $800.57 226 0.1 45 BULK-9b776ccf
18444 Bulk Product f0a98358 Toys & Games $499.50 489 1.0 53 BULK-5736bfea
18445 Bulk Product b56da28c Toys & Games $538.62 185 3.7 39 BULK-3149ac2c
18446 Bulk Product f1493c86 Sports & Outdoors $908.55 336 1.3 70 BULK-12d0990c
18447 Bulk Product c3a4993f Home & Garden $364.94 162 4.9 48 BULK-ee0a28d9
18448 Bulk Product a19df9a7 Clothing $842.58 79 3.8 86 BULK-6312a51b
18449 Bulk Product 3a9c8d9b Home & Garden $23.63 440 4.1 24 BULK-b9b491f8
18450 Bulk Product c2fe0ffd Sports & Outdoors $434.21 259 3.1 51 BULK-32fa60a5
18451 Bulk Product c363f47e Toys & Games $145.70 185 2.2 62 BULK-3268d43a
18452 Bulk Product b4085335 Home & Garden $930.70 330 1.4 62 BULK-7e63b9bd
18453 Bulk Product 559b0123 Sports & Outdoors $959.28 230 5.0 44 BULK-1ec5463e
18454 Bulk Product f391b53d Books $441.02 243 4.3 82 BULK-499b684d
18455 Bulk Product e806e2d4 Toys & Games $656.46 50 1.9 37 BULK-ba544ae4
18456 Bulk Product 00e1446c Clothing $150.11 399 2.2 88 BULK-d9ebdbf4
18457 Bulk Product 1fdcf081 Home & Garden $28.44 274 4.6 6 BULK-e5862825
18458 Bulk Product 6feb3cc3 Clothing $518.55 94 0.3 51 BULK-f87e0d7e
18459 Bulk Product 50db9696 Home & Garden $732.81 379 1.2 35 BULK-8d4d53bb
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