Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

367 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 367 Results Showing 9151 - 9175 of 24441

ID Name Category Price Stock Rating Reviews SKU
9710 Bulk Product ebf035cf Home & Garden $345.95 368 2.3 7 BULK-3c880558
9711 Bulk Product c1bafb46 Home & Garden $509.35 103 1.7 64 BULK-5b454a27
9712 Bulk Product 59c9c665 Clothing $214.84 418 1.7 67 BULK-ec306db4
9713 Bulk Product 0c742997 Sports & Outdoors $840.25 179 2.4 8 BULK-f7f12f22
9714 Bulk Product fd287fbf Books $453.41 188 4.3 10 BULK-b5d6bbc1
9715 Bulk Product b58ee382 Sports & Outdoors $405.38 27 3.5 58 BULK-924fb430
9716 Bulk Product 3c47e8e1 Sports & Outdoors $926.00 106 0.7 66 BULK-dd9bab60
9717 Bulk Product 15c7e33e Books $611.52 264 2.8 43 BULK-f2d35441
9718 Bulk Product 1a1b2ae2 Sports & Outdoors $270.37 387 0.8 77 BULK-214c493a
9719 Bulk Product a763da14 Toys & Games $62.79 320 0.4 28 BULK-9596dac5
9720 Bulk Product ea24d8ab Sports & Outdoors $46.85 300 4.2 70 BULK-213a9ab0
9721 Bulk Product 2cd0fbcb Toys & Games $182.85 386 3.8 58 BULK-28a7346e
9722 Bulk Product 3e201c7a Sports & Outdoors $305.53 23 1.1 20 BULK-53cd82d0
9723 Bulk Product 0113494c Home & Garden $534.72 202 3.7 48 BULK-d3f44821
9724 Bulk Product 9f98fe33 Home & Garden $668.20 429 2.0 73 BULK-4ccbf92f
9725 Bulk Product 88840b04 Toys & Games $431.67 100 2.6 12 BULK-b1e6f18c
9726 Bulk Product 32817b29 Electronics $962.89 151 1.6 46 BULK-042e9f5c
9727 Bulk Product 5f57d095 Home & Garden $87.96 485 0.8 66 BULK-3c878d80
9728 Bulk Product c8985167 Books $109.12 439 4.3 3 BULK-4c96e6a8
9729 Bulk Product f31716ce Electronics $361.22 318 0.4 85 BULK-94a5f575
9730 Bulk Product 3fe3ac48 Sports & Outdoors $227.67 25 2.4 88 BULK-85337f75
9731 Bulk Product 6eb50f4f Home & Garden $874.19 387 2.4 57 BULK-d67118d0
9732 Bulk Product 85ce5af0 Toys & Games $116.06 395 4.6 2 BULK-6bdcc9c9
9733 Bulk Product 79baa0e8 Toys & Games $773.35 226 0.7 47 BULK-523c64b1
9734 Bulk Product 18fd7b31 Books $280.15 450 1.1 12 BULK-c70595b7
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