Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

363 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 363 Results Showing 9051 - 9075 of 24441

ID Name Category Price Stock Rating Reviews SKU
9610 Bulk Product 0cbf4949 Sports & Outdoors $952.00 163 3.1 62 BULK-ce41aa86
9611 Bulk Product 9dfe51af Electronics $279.85 277 1.0 62 BULK-b332fe96
9612 Bulk Product 946ab549 Home & Garden $881.78 323 1.9 72 BULK-c1e59f4b
9613 Bulk Product c502e40e Electronics $610.43 478 4.6 27 BULK-6e6172b3
9614 Bulk Product 1a51b0bd Toys & Games $507.46 172 1.9 25 BULK-5989af0b
9615 Bulk Product e61da4a2 Sports & Outdoors $868.82 423 0.8 78 BULK-220fc2af
9616 Bulk Product 2e00664e Home & Garden $869.55 305 1.6 58 BULK-1b3e6b17
9617 Bulk Product 3d9260dc Home & Garden $809.72 164 0.5 12 BULK-aa955800
9618 Bulk Product 57128f37 Electronics $879.57 291 1.5 54 BULK-802a6713
9619 Bulk Product 9a0092c7 Electronics $421.82 238 0.5 66 BULK-5f13a9b4
9620 Bulk Product 700889d4 Electronics $565.75 475 1.8 75 BULK-a670ce9f
9621 Bulk Product f4650374 Clothing $451.28 152 4.5 84 BULK-1990a7d0
9622 Bulk Product bf56a68f Books $764.29 139 1.5 9 BULK-376c6e34
9623 Bulk Product 401c3f2d Home & Garden $269.16 228 3.3 66 BULK-fe43944e
9624 Bulk Product d0b8a6c4 Sports & Outdoors $696.17 240 3.0 44 BULK-efcb504b
9625 Bulk Product bc6a0450 Home & Garden $446.44 171 2.3 65 BULK-657c04cb
9626 Bulk Product b54c1a03 Clothing $251.13 397 4.5 54 BULK-d5f4ae90
9627 Bulk Product 2e93c0ea Toys & Games $728.55 498 4.9 30 BULK-9d95b645
9628 Bulk Product e4d34c5c Clothing $758.32 2 4.3 10 BULK-e3091dfe
9629 Bulk Product 5dd73992 Books $436.35 217 0.2 14 BULK-4fcef501
9630 Bulk Product 0dbc69ed Toys & Games $417.21 89 4.6 51 BULK-da2df162
9631 Bulk Product e4084b52 Home & Garden $71.35 385 3.9 12 BULK-81169e3d
9632 Bulk Product a2e60417 Sports & Outdoors $645.98 258 5.0 31 BULK-e8e4c782
9633 Bulk Product eb8bde38 Toys & Games $356.61 45 0.9 14 BULK-6f9c6a0e
9634 Bulk Product f7c11bac Clothing $154.87 464 3.6 94 BULK-6039a0a6
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