Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

56 ms

Page Size

25

Current Page

877 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 877 Results Showing 21901 - 21925 of 24441

ID Name Category Price Stock Rating Reviews SKU
22460 Bulk Product 0a944862 Toys & Games $157.26 169 2.2 70 BULK-8913a3e2
22461 Bulk Product 661e6c6b Books $428.63 483 1.1 91 BULK-e63d0d99
22462 Bulk Product a732a624 Electronics $181.64 475 4.9 55 BULK-6500794c
22463 Bulk Product cf650fbb Clothing $93.56 50 0.5 12 BULK-ed92327c
22464 Bulk Product cd3c845c Books $169.94 143 0.3 91 BULK-46b78746
22465 Bulk Product fe864817 Clothing $246.23 329 0.6 98 BULK-c9bb98c0
22466 Bulk Product a3b15760 Electronics $253.59 457 1.6 36 BULK-2f1b1792
22467 Bulk Product c8ff6d75 Clothing $834.73 8 0.0 92 BULK-5b1ecd11
22468 Bulk Product e670ee2f Sports & Outdoors $992.08 426 0.5 63 BULK-3dbd93bc
22469 Bulk Product 8f42b5f5 Sports & Outdoors $102.46 199 0.4 44 BULK-f1005505
22470 Bulk Product fcc147c2 Sports & Outdoors $351.27 91 4.3 33 BULK-6d6e00db
22471 Bulk Product d8dbec45 Toys & Games $325.83 467 0.6 16 BULK-6d9d1609
22472 Bulk Product 14ffc4c2 Books $968.28 201 1.3 66 BULK-b7a49469
22473 Bulk Product 6195c0fa Sports & Outdoors $858.96 418 4.3 75 BULK-8f8ecbbe
22474 Bulk Product cab71947 Books $569.68 372 2.2 50 BULK-8ff4186a
22475 Bulk Product 9a9bbb87 Books $338.03 427 2.4 15 BULK-4b5938e4
22476 Bulk Product 12ed070a Sports & Outdoors $79.14 165 3.1 14 BULK-d2886b51
22477 Bulk Product 5797f19c Sports & Outdoors $146.58 373 4.0 63 BULK-87ae10b8
22478 Bulk Product 07eab261 Books $567.42 341 4.4 99 BULK-218e05d4
22479 Bulk Product a4ad83fe Sports & Outdoors $644.00 175 2.7 40 BULK-148bf691
22480 Bulk Product b6ce691b Electronics $428.92 75 2.1 74 BULK-ad997565
22481 Bulk Product efc4e516 Electronics $119.33 161 4.9 8 BULK-b6f3f3ef
22482 Bulk Product f6196851 Sports & Outdoors $385.41 422 0.7 26 BULK-f23b91c3
22483 Bulk Product 53bb40c3 Sports & Outdoors $419.14 30 3.2 73 BULK-d9c33fe0
22484 Bulk Product 6739661a Clothing $965.12 183 1.8 60 BULK-b169dbcc
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