Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

607 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 607 Results Showing 15151 - 15175 of 24441

ID Name Category Price Stock Rating Reviews SKU
15710 Bulk Product 9a1d021a Clothing $183.15 3 4.8 13 BULK-6e3252e4
15711 Bulk Product 89faef70 Toys & Games $350.41 418 3.4 44 BULK-c840e683
15712 Bulk Product e5344f71 Sports & Outdoors $225.80 290 3.8 67 BULK-62977b1c
15713 Bulk Product ad69d60f Clothing $17.24 191 3.4 88 BULK-2b091f01
15714 Bulk Product 95767d62 Clothing $906.10 11 1.1 20 BULK-d716038e
15715 Bulk Product 482875bd Home & Garden $515.89 16 1.5 77 BULK-122b02a8
15716 Bulk Product 0e9797cb Clothing $716.90 451 0.8 80 BULK-31c8f0b0
15717 Bulk Product 55ba791b Books $910.86 404 2.4 58 BULK-8e0029a2
15718 Bulk Product 3d28cd88 Sports & Outdoors $976.91 142 0.1 43 BULK-1cf926b3
15719 Bulk Product 51fb47d6 Home & Garden $245.48 121 3.4 80 BULK-d11e8d5e
15720 Bulk Product ab9bdd4a Electronics $944.61 182 1.5 8 BULK-392b51a9
15721 Bulk Product 96d93f43 Books $453.64 334 2.7 17 BULK-806b3092
15722 Bulk Product 895a1da5 Toys & Games $878.29 153 1.0 77 BULK-935f8229
15723 Bulk Product 1282a0a6 Toys & Games $366.89 101 4.6 15 BULK-eb24deed
15724 Bulk Product bbdaab10 Electronics $924.52 121 1.7 99 BULK-4d932a19
15725 Bulk Product 8a996791 Electronics $107.89 6 0.5 84 BULK-39ce5627
15726 Bulk Product c1dd0691 Sports & Outdoors $740.87 348 4.0 7 BULK-bff11510
15727 Bulk Product 5e0b0a01 Books $46.84 444 3.2 23 BULK-d4106d59
15728 Bulk Product b6353996 Toys & Games $988.09 465 2.3 5 BULK-6d307ac0
15729 Bulk Product d4e649ab Home & Garden $336.48 465 2.4 42 BULK-975fd136
15730 Bulk Product d9d10a48 Home & Garden $406.65 38 4.7 64 BULK-8a467cbd
15731 Bulk Product dfd23f89 Electronics $535.67 248 4.0 44 BULK-77260649
15732 Bulk Product 68c4bfee Toys & Games $987.25 261 2.6 27 BULK-67ced8db
15733 Bulk Product 2ef4a13a Sports & Outdoors $569.76 160 4.2 95 BULK-f8f5618b
15734 Bulk Product d9ed7a04 Sports & Outdoors $134.58 23 4.1 50 BULK-8c1de865
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