Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

34 ms

Page Size

25

Current Page

464 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 464 Results Showing 11576 - 11600 of 24441

ID Name Category Price Stock Rating Reviews SKU
12135 Bulk Product e3d8ffee Electronics $580.15 68 4.7 34 BULK-f7222527
12136 Bulk Product 1ddb10a9 Home & Garden $851.86 265 0.1 41 BULK-8db6e52b
12137 Bulk Product 2b60f23f Home & Garden $815.66 14 4.6 7 BULK-75b56adf
12138 Bulk Product 0d699360 Home & Garden $686.14 42 2.6 15 BULK-8bb3b312
12139 Bulk Product e54f988f Toys & Games $731.37 144 1.3 54 BULK-09520305
12140 Bulk Product 9efa0482 Electronics $496.81 418 4.4 68 BULK-2f673b7b
12141 Bulk Product c571e533 Clothing $643.12 198 4.0 76 BULK-b5b41023
12142 Bulk Product a183d385 Books $790.39 481 4.4 96 BULK-c0210a00
12143 Bulk Product 9fc37ff9 Sports & Outdoors $99.58 288 1.2 92 BULK-fff8cc3f
12144 Bulk Product 19c603d3 Sports & Outdoors $559.87 143 2.2 90 BULK-002a5af8
12145 Bulk Product 0660cd03 Electronics $749.91 354 4.1 27 BULK-34849c69
12146 Bulk Product 246fe1c6 Electronics $702.65 118 2.7 27 BULK-15d99c14
12147 Bulk Product 247ce5b5 Toys & Games $94.13 327 4.0 22 BULK-98c88041
12148 Bulk Product 1679240a Toys & Games $505.43 172 2.1 75 BULK-cf57d8da
12149 Bulk Product af8076e1 Sports & Outdoors $725.90 343 2.8 10 BULK-cc9c95ad
12150 Bulk Product 90158656 Toys & Games $527.45 8 1.4 91 BULK-9469ef90
12151 Bulk Product 872f97e5 Books $992.06 403 3.8 96 BULK-897be30c
12152 Bulk Product bcc0115c Sports & Outdoors $906.65 477 4.5 27 BULK-2cc0f3d2
12153 Bulk Product e517bc93 Clothing $788.76 475 0.2 99 BULK-0d5d77c7
12154 Bulk Product 7f2c0630 Home & Garden $322.33 312 1.2 26 BULK-63ac8431
12155 Bulk Product be3ab33a Clothing $935.02 35 0.0 2 BULK-ba3803c5
12156 Bulk Product cd7fafc2 Home & Garden $215.42 489 3.4 22 BULK-04432052
12157 Bulk Product 72e24975 Books $73.04 143 4.7 98 BULK-03cac2c9
12158 Bulk Product d3d19d2f Home & Garden $133.79 324 4.1 96 BULK-dc7c0c33
12159 Bulk Product 17916d98 Toys & Games $312.98 39 0.9 39 BULK-d3357ef6
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