Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

462 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 462 Results Showing 11526 - 11550 of 24441

ID Name Category Price Stock Rating Reviews SKU
12085 Bulk Product e867e239 Books $828.62 444 4.3 17 BULK-3818bde3
12086 Bulk Product 8f452c41 Home & Garden $150.55 208 4.5 48 BULK-54a4add2
12087 Bulk Product bfd402a1 Sports & Outdoors $915.07 171 4.8 71 BULK-c21b4262
12088 Bulk Product 36dff6fb Sports & Outdoors $10.53 401 3.9 21 BULK-67144ad1
12089 Bulk Product 9e76bda0 Toys & Games $139.00 212 1.0 73 BULK-bbb8f388
12090 Bulk Product 707fd188 Home & Garden $590.82 472 3.9 69 BULK-adc05ba8
12091 Bulk Product 53a104d5 Books $347.04 461 2.7 20 BULK-16ff44ff
12092 Bulk Product f538e44a Clothing $107.22 209 3.5 52 BULK-67cd7070
12093 Bulk Product 8959d09a Clothing $633.29 174 1.2 99 BULK-dabc7476
12094 Bulk Product b2536f80 Electronics $87.75 138 3.9 61 BULK-d905a4d8
12095 Bulk Product 5b820e9b Books $902.26 76 4.3 62 BULK-1db2ce4c
12096 Bulk Product bbe4a959 Toys & Games $945.52 133 1.3 83 BULK-9c1aff49
12097 Bulk Product 00281e54 Sports & Outdoors $938.81 471 4.9 75 BULK-285f1875
12098 Bulk Product ad8bcfcd Toys & Games $18.67 350 1.7 69 BULK-c877481c
12099 Bulk Product 0d0bdf01 Home & Garden $914.80 210 0.8 40 BULK-d3b1626d
12100 Bulk Product 55e8f4d3 Electronics $829.24 335 0.7 97 BULK-79e2383b
12101 Bulk Product c3d138c1 Toys & Games $525.34 450 4.4 91 BULK-55061e52
12102 Bulk Product ca1b866f Books $59.45 239 3.0 10 BULK-9dcb9b2e
12103 Bulk Product 12d06e60 Clothing $951.92 143 1.5 24 BULK-bf5b1b13
12104 Bulk Product 8f148103 Home & Garden $480.06 75 1.5 65 BULK-dc11920b
12105 Bulk Product f83aceef Home & Garden $442.40 12 4.3 99 BULK-974c63f4
12106 Bulk Product fab2cfa6 Home & Garden $783.74 163 3.6 79 BULK-b6647641
12107 Bulk Product e881f354 Electronics $381.02 409 0.1 9 BULK-87e22281
12108 Bulk Product 2d35ca3d Sports & Outdoors $652.91 130 1.2 47 BULK-ee12949b
12109 Bulk Product c37fc572 Clothing $133.81 269 3.1 68 BULK-5757545c
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