Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

24 ms

Page Size

25

Current Page

843 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 843 Results Showing 21051 - 21075 of 24441

ID Name Category Price Stock Rating Reviews SKU
21610 Bulk Product 638134c2 Clothing $464.03 102 2.8 68 BULK-59557243
21611 Bulk Product 3fa347a3 Home & Garden $720.47 388 4.9 0 BULK-5debe2df
21612 Bulk Product b7ad9adc Electronics $787.88 23 4.2 67 BULK-1daa7401
21613 Bulk Product a73e98f0 Clothing $969.53 164 0.2 47 BULK-a5cd7aa3
21614 Bulk Product 54edd1bf Home & Garden $322.97 429 2.2 1 BULK-7791664d
21615 Bulk Product 15ca850f Toys & Games $637.59 455 3.3 2 BULK-0be02946
21616 Bulk Product 8f7b60f6 Sports & Outdoors $358.83 50 0.9 67 BULK-41eeef7e
21617 Bulk Product 2ca1655e Books $397.72 437 1.3 74 BULK-0299b133
21618 Bulk Product be3bd040 Clothing $627.99 212 2.2 45 BULK-8c770936
21619 Bulk Product 60bc0339 Electronics $469.57 350 3.6 1 BULK-f1ba9b08
21620 Bulk Product 7e6eee19 Books $121.90 268 3.1 94 BULK-ec9f748c
21621 Bulk Product ea408054 Books $742.71 122 2.3 18 BULK-5dde7762
21622 Bulk Product 005668b1 Toys & Games $372.40 239 3.4 19 BULK-eb655def
21623 Bulk Product ae82a4ee Books $888.46 192 2.4 64 BULK-77cca73d
21624 Bulk Product a1d5e382 Sports & Outdoors $907.24 181 2.2 17 BULK-36019cdb
21625 Bulk Product 4cdf8305 Sports & Outdoors $941.82 485 3.0 48 BULK-7e9fdc4e
21626 Bulk Product 9a11192d Home & Garden $191.44 201 1.8 65 BULK-a707ca39
21627 Bulk Product 1f929491 Clothing $319.38 27 2.5 30 BULK-8ef4f813
21628 Bulk Product f7a2e3e9 Clothing $370.08 31 0.3 70 BULK-9b828b5d
21629 Bulk Product 8976cd39 Home & Garden $952.50 153 0.2 18 BULK-dc1dcb64
21630 Bulk Product 41cb4a9f Sports & Outdoors $320.38 144 4.2 75 BULK-9c0bd3eb
21631 Bulk Product cf10bb83 Sports & Outdoors $271.21 117 3.2 72 BULK-183e3fd0
21632 Bulk Product d13c7048 Toys & Games $53.98 465 1.9 51 BULK-43facc30
21633 Bulk Product 93739619 Clothing $973.83 331 2.5 55 BULK-e7141fbc
21634 Bulk Product 43c47ab7 Electronics $116.22 443 3.0 15 BULK-5209e42c
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