Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

594 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 594 Results Showing 14826 - 14850 of 24441

ID Name Category Price Stock Rating Reviews SKU
15385 Bulk Product f21ec43b Sports & Outdoors $658.40 50 2.1 16 BULK-84108125
15386 Bulk Product 5e7b1fdc Home & Garden $865.81 348 4.9 2 BULK-aa083d9b
15387 Bulk Product 4ebe0aee Home & Garden $187.84 110 1.7 21 BULK-60104b4d
15388 Bulk Product 25a99ae4 Toys & Games $555.66 496 0.5 31 BULK-ed832ba6
15389 Bulk Product d9452c2d Toys & Games $163.78 210 1.5 96 BULK-30a7ae3c
15390 Bulk Product 7b7843a7 Sports & Outdoors $201.32 63 0.8 46 BULK-ab7609a0
15391 Bulk Product a73271c6 Toys & Games $264.38 488 2.5 1 BULK-2d399918
15392 Bulk Product 783f221c Clothing $570.51 32 2.9 60 BULK-fa459e85
15393 Bulk Product 93b5fa71 Clothing $58.82 361 0.6 87 BULK-49127ccd
15394 Bulk Product 46ee2564 Books $17.05 102 1.5 58 BULK-27e359e7
15395 Bulk Product 49579f68 Electronics $719.73 29 3.0 46 BULK-903e48ca
15396 Bulk Product c0aed4fc Clothing $504.66 320 0.3 89 BULK-2b27b7c2
15397 Bulk Product 58bc9ed9 Toys & Games $790.04 158 3.3 52 BULK-01e7c2c0
15398 Bulk Product fda5cf05 Sports & Outdoors $958.28 286 4.6 59 BULK-5006b102
15399 Bulk Product 3ce2f00a Clothing $832.28 490 4.5 32 BULK-1a550f7c
15400 Bulk Product 8faace0f Sports & Outdoors $187.21 130 0.9 24 BULK-eb9001fd
15401 Bulk Product 91c08c9b Books $413.07 413 1.0 59 BULK-c3b930de
15402 Bulk Product 767c3496 Toys & Games $85.59 245 3.2 93 BULK-c3a943a4
15403 Bulk Product 96c96042 Sports & Outdoors $549.12 401 0.8 14 BULK-145eb670
15404 Bulk Product 16a12e5a Electronics $965.43 382 1.5 39 BULK-3066f5ac
15405 Bulk Product ee4b2f63 Sports & Outdoors $496.24 388 4.4 46 BULK-b63797fe
15406 Bulk Product 5931db8b Home & Garden $586.95 337 1.5 88 BULK-0624248b
15407 Bulk Product 14ac95fb Toys & Games $661.45 31 4.8 95 BULK-28f4128e
15408 Bulk Product 8f2cd5fb Books $233.89 458 2.7 89 BULK-3f35665c
15409 Bulk Product df801d6b Electronics $140.45 371 1.9 46 BULK-bffa593d
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