Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

387 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 387 Results Showing 9651 - 9675 of 24441

ID Name Category Price Stock Rating Reviews SKU
10210 Bulk Product 1ac09637 Electronics $107.84 61 0.1 92 BULK-706ad2ac
10211 Bulk Product 08b3c82d Books $889.25 425 3.9 56 BULK-f9041784
10212 Bulk Product 61a4441b Clothing $549.75 370 4.4 57 BULK-eea62794
10213 Bulk Product 1e514d02 Sports & Outdoors $84.08 24 3.7 28 BULK-645d28f6
10214 Bulk Product 3e64aeae Sports & Outdoors $522.52 100 0.3 65 BULK-87c5188f
10215 Bulk Product 760889f3 Home & Garden $326.27 98 0.4 59 BULK-cc7d10bb
10216 Bulk Product f6f0b627 Toys & Games $792.67 278 3.2 22 BULK-54ba8905
10217 Bulk Product 5d4108c7 Home & Garden $176.66 413 1.2 93 BULK-0b7f6a60
10218 Bulk Product e5fbe284 Sports & Outdoors $896.84 164 2.8 59 BULK-22e44b86
10219 Bulk Product 1c8dc056 Books $300.49 272 3.9 76 BULK-aa64d517
10220 Bulk Product 5ecaf882 Home & Garden $166.91 335 3.3 23 BULK-eb08c217
10221 Bulk Product 741e6561 Sports & Outdoors $903.87 256 0.6 79 BULK-cae494d9
10222 Bulk Product 3051fdd8 Books $229.59 322 3.0 96 BULK-18464c99
10223 Bulk Product a6f50289 Toys & Games $104.40 99 4.2 92 BULK-650e101d
10224 Bulk Product 60d70e35 Clothing $984.19 23 2.4 71 BULK-eec0c6f1
10225 Bulk Product 7976351d Sports & Outdoors $552.94 247 4.2 44 BULK-4eda050c
10226 Bulk Product 9a2da548 Toys & Games $49.40 469 3.8 99 BULK-03916ac1
10227 Bulk Product 32244346 Clothing $158.61 316 1.2 49 BULK-1bcd8c9e
10228 Bulk Product a76ae8c0 Sports & Outdoors $309.53 374 1.6 2 BULK-3b1b6185
10229 Bulk Product e242768e Home & Garden $637.66 106 3.3 43 BULK-9c03c6e7
10230 Bulk Product 48659c6b Clothing $451.48 356 1.0 87 BULK-fb6fbc6f
10231 Bulk Product aaff5e3e Toys & Games $373.51 355 2.4 63 BULK-8d85bc8e
10232 Bulk Product 4562dcd2 Clothing $503.86 17 2.1 64 BULK-d02747ea
10233 Bulk Product de477097 Toys & Games $616.05 101 4.8 79 BULK-d3c5d283
10234 Bulk Product b39f1d48 Toys & Games $762.67 316 4.5 4 BULK-93548f82
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