Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

496 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 496 Results Showing 12376 - 12400 of 24441

ID Name Category Price Stock Rating Reviews SKU
12935 Bulk Product 1f80c086 Toys & Games $716.23 318 3.9 61 BULK-ee850704
12936 Bulk Product ec726240 Home & Garden $898.78 404 2.6 77 BULK-91660cb9
12937 Bulk Product f10a6700 Clothing $529.12 243 0.0 55 BULK-c4d983ce
12938 Bulk Product 35c1e1c6 Electronics $997.57 185 2.8 37 BULK-43377687
12939 Bulk Product e7bfc549 Clothing $132.69 450 2.3 48 BULK-ea300715
12940 Bulk Product e10cefbb Toys & Games $409.01 316 1.6 92 BULK-ddc7c169
12941 Bulk Product cc4436e1 Clothing $506.07 434 2.6 73 BULK-d6dc3f3f
12942 Bulk Product f831c4b0 Home & Garden $349.40 274 2.1 63 BULK-fe4d12fd
12943 Bulk Product 790829cc Sports & Outdoors $555.98 358 3.1 63 BULK-10aaf25a
12944 Bulk Product 66b2bc5c Home & Garden $826.82 284 1.4 69 BULK-24428305
12945 Bulk Product a12b164c Clothing $418.99 356 1.0 83 BULK-99a77360
12946 Bulk Product 4a110e87 Books $429.53 419 4.8 14 BULK-4bf1735c
12947 Bulk Product 3a29bf7b Clothing $401.07 148 3.8 21 BULK-7fc55d2b
12948 Bulk Product 07895b70 Clothing $953.24 92 0.2 55 BULK-4960ecd6
12949 Bulk Product e3dc1396 Books $538.90 218 1.9 3 BULK-a54573e2
12950 Bulk Product 907f8cbf Sports & Outdoors $250.41 269 0.5 94 BULK-843ead1b
12951 Bulk Product 0fbc226f Home & Garden $857.56 111 2.9 42 BULK-c17fdc21
12952 Bulk Product 56c8e82c Electronics $583.89 32 4.1 41 BULK-dd3a5487
12953 Bulk Product 510cd3a2 Sports & Outdoors $66.50 491 2.3 46 BULK-e3efb3c5
12954 Bulk Product 9c675c93 Home & Garden $867.38 11 1.8 22 BULK-d9718704
12955 Bulk Product 5d5aca00 Toys & Games $160.56 105 2.7 31 BULK-2eb8b18d
12956 Bulk Product d97ed136 Books $841.18 210 3.0 73 BULK-0e69ee1c
12957 Bulk Product 3c560e93 Electronics $327.22 152 4.4 15 BULK-62c4ace3
12958 Bulk Product 147c262b Clothing $854.16 347 3.9 65 BULK-eb15bab3
12959 Bulk Product 24317f01 Toys & Games $408.50 209 1.6 39 BULK-bdd0057e
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