Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

725 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 725 Results Showing 18101 - 18125 of 24441

ID Name Category Price Stock Rating Reviews SKU
18660 Bulk Product de5e1623 Home & Garden $786.37 414 3.2 75 BULK-a4f903bd
18661 Bulk Product a949ae1b Electronics $634.83 130 4.1 28 BULK-3698bd5e
18662 Bulk Product 8bc6161e Books $350.43 481 0.6 58 BULK-78d4cf6f
18663 Bulk Product b7ba2755 Sports & Outdoors $597.21 208 2.6 5 BULK-2350359a
18664 Bulk Product fc5c3681 Home & Garden $217.14 111 4.0 91 BULK-51c16126
18665 Bulk Product bd9121c6 Electronics $238.76 20 3.7 38 BULK-45576ea3
18666 Bulk Product 653466c9 Sports & Outdoors $784.90 288 4.4 71 BULK-6fce11eb
18667 Bulk Product 139585f6 Sports & Outdoors $673.40 240 3.7 50 BULK-4448e40d
18668 Bulk Product 2b0649ff Sports & Outdoors $31.93 436 0.2 25 BULK-cb8aa036
18669 Bulk Product 808d9911 Sports & Outdoors $863.17 403 1.3 55 BULK-0ae245a3
18670 Bulk Product f26aa4af Toys & Games $521.84 141 2.7 16 BULK-0f140f01
18671 Bulk Product 414d0b6d Home & Garden $374.88 227 3.9 21 BULK-a476f75a
18672 Bulk Product a7e10909 Books $325.35 73 0.1 22 BULK-69c9f96c
18673 Bulk Product cb757ee9 Clothing $858.76 66 3.9 39 BULK-a2c79fcb
18674 Bulk Product 5a933d70 Electronics $955.99 82 4.4 76 BULK-e070d1bf
18675 Bulk Product af863b31 Toys & Games $548.09 421 1.1 87 BULK-3dc627e7
18676 Bulk Product 158c9c1e Clothing $769.27 76 1.7 55 BULK-f8d863c7
18677 Bulk Product ed4eb06b Sports & Outdoors $921.45 160 1.0 38 BULK-ebf506c3
18678 Bulk Product 0e91c69a Sports & Outdoors $186.00 148 2.3 60 BULK-6e8a587c
18679 Bulk Product ab140e9f Electronics $97.45 447 2.1 90 BULK-18b3ae70
18680 Bulk Product 7b8a407f Sports & Outdoors $700.68 24 2.3 4 BULK-64808372
18681 Bulk Product 0abab3c0 Sports & Outdoors $445.24 83 1.5 42 BULK-875e1c46
18682 Bulk Product c90ac812 Home & Garden $611.85 275 4.4 22 BULK-3ae8e4ee
18683 Bulk Product 3fbe7a67 Home & Garden $760.75 259 0.1 34 BULK-a528c976
18684 Bulk Product 16f40601 Sports & Outdoors $479.21 33 3.0 8 BULK-65fc2ada
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