Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

194 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 194 Results Showing 4826 - 4850 of 24441

ID Name Category Price Stock Rating Reviews SKU
5385 Bulk Product 3db97a6c Clothing $22.69 373 1.4 8 BULK-94a53d8f
5386 Bulk Product a386cd33 Toys & Games $68.07 74 1.1 62 BULK-875d127f
5387 Bulk Product 172a9688 Electronics $270.01 63 1.8 82 BULK-5e2086c6
5388 Bulk Product 6c10ecc4 Home & Garden $863.60 255 4.2 40 BULK-bb7d08b2
5389 Bulk Product 038b99de Clothing $344.07 488 3.2 84 BULK-58f6ce59
5390 Bulk Product 52b6ee3b Electronics $100.96 231 0.7 73 BULK-6c90a9e2
5391 Bulk Product 3b1a8ca3 Electronics $894.46 98 0.4 30 BULK-b6068037
5392 Bulk Product 4a3264f3 Books $201.19 18 1.5 68 BULK-b1da40cb
5393 Bulk Product 522ea716 Electronics $809.29 326 4.4 93 BULK-4c5a15b2
5394 Bulk Product 6c84f99e Electronics $672.89 110 1.7 90 BULK-e72b97fa
5395 Bulk Product 5006a289 Toys & Games $273.92 463 4.0 29 BULK-361559b3
5396 Bulk Product 2da51c76 Electronics $720.88 316 1.9 7 BULK-f3d25db4
5397 Bulk Product 4e0fe2e7 Clothing $28.05 77 2.6 80 BULK-21665c5c
5398 Bulk Product 3e8a2189 Sports & Outdoors $876.03 265 4.4 12 BULK-d06892db
5399 Bulk Product 0cb05b08 Home & Garden $802.60 209 2.2 73 BULK-950434bf
5400 Bulk Product caa8ac29 Clothing $162.37 53 0.6 12 BULK-32a51c54
5401 Bulk Product ac889c90 Electronics $559.23 278 4.2 75 BULK-93fc5102
5402 Bulk Product 5ba250da Clothing $992.46 63 2.0 45 BULK-ea8e6e07
5403 Bulk Product d275b242 Toys & Games $190.30 429 3.3 82 BULK-1705dba0
5404 Bulk Product bbfebfd4 Clothing $743.90 79 4.2 81 BULK-2412eaf5
5405 Bulk Product a29148fb Sports & Outdoors $634.25 470 0.3 32 BULK-ae203cc7
5406 Bulk Product 1d5e48b9 Books $390.52 198 1.9 72 BULK-0794158c
5407 Bulk Product 84948943 Books $78.67 302 0.1 14 BULK-83c46f0a
5408 Bulk Product be8a294c Toys & Games $54.00 50 1.4 61 BULK-7b67a640
5409 Bulk Product a356ab53 Books $629.51 187 0.6 53 BULK-0f5eede0
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