Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

107 ms

Page Size

25

Current Page

681 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 681 Results Showing 17001 - 17025 of 24441

ID Name Category Price Stock Rating Reviews SKU
17560 Bulk Product 9d6e0c2c Sports & Outdoors $420.35 47 3.7 60 BULK-49b433db
17561 Bulk Product 0243570c Toys & Games $694.81 195 1.5 7 BULK-8ae88a7d
17562 Bulk Product 9a999498 Home & Garden $50.89 331 2.4 85 BULK-4661f6c6
17563 Bulk Product 2feb9edf Sports & Outdoors $416.14 407 3.4 18 BULK-f6ab22dc
17564 Bulk Product f7491a91 Sports & Outdoors $863.97 230 0.8 78 BULK-1b296a6e
17565 Bulk Product d9dc0f62 Clothing $71.62 467 1.5 7 BULK-ee78e7f2
17566 Bulk Product 97c163d6 Books $632.92 223 0.9 37 BULK-1c33315b
17567 Bulk Product 76300309 Books $22.91 322 1.1 81 BULK-9bc9ba3d
17568 Bulk Product 18cd5e8c Clothing $361.23 250 2.0 41 BULK-abb3359f
17569 Bulk Product 8b362a8b Toys & Games $242.23 32 4.5 11 BULK-4e17636f
17570 Bulk Product 12142a71 Sports & Outdoors $389.56 322 2.6 32 BULK-5fe720eb
17571 Bulk Product fe6da4fa Clothing $113.75 82 1.1 47 BULK-c9f36a3b
17572 Bulk Product 6cc64c05 Toys & Games $209.52 107 3.1 14 BULK-42612ca5
17573 Bulk Product 9f520705 Sports & Outdoors $340.28 158 2.6 2 BULK-557c335d
17574 Bulk Product 310443d3 Toys & Games $114.79 493 3.6 84 BULK-d3e323cc
17575 Bulk Product 289e0d7d Clothing $421.79 214 2.9 36 BULK-1b6a6b59
17576 Bulk Product ceea3b72 Books $392.04 383 4.4 93 BULK-b05a80cc
17577 Bulk Product ae68207e Books $336.92 171 2.8 33 BULK-a3cdd959
17578 Bulk Product 2a37ee60 Home & Garden $594.19 250 2.1 33 BULK-d6482343
17579 Bulk Product cda3c2b4 Clothing $553.41 143 1.5 58 BULK-e568dcd6
17580 Bulk Product 2f6455bc Books $587.40 8 4.4 4 BULK-a65a772b
17581 Bulk Product fd05f85a Home & Garden $583.81 475 2.9 26 BULK-d38f774e
17582 Bulk Product dcaf155e Toys & Games $198.41 301 2.1 42 BULK-4899eace
17583 Bulk Product 2b083628 Sports & Outdoors $914.05 372 4.2 98 BULK-9b9898bd
17584 Bulk Product ce66926b Electronics $636.47 41 2.9 45 BULK-6e0b07c8
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