Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

634 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 634 Results Showing 15826 - 15850 of 24441

ID Name Category Price Stock Rating Reviews SKU
16385 Bulk Product e5d21a48 Sports & Outdoors $377.99 115 2.7 18 BULK-ae4cbd01
16386 Bulk Product e39d39d8 Clothing $910.49 9 4.8 82 BULK-1ba082e6
16387 Bulk Product d1d3c852 Clothing $146.46 133 3.4 76 BULK-378228b6
16388 Bulk Product 30ea293f Books $266.89 173 1.2 56 BULK-3fc1b141
16389 Bulk Product a2258f62 Clothing $774.82 221 4.7 57 BULK-2a0b1879
16390 Bulk Product 85c5ca47 Clothing $577.08 8 0.2 94 BULK-2459d602
16391 Bulk Product 0754581e Books $314.33 374 1.3 80 BULK-f5be1279
16392 Bulk Product 835901f6 Clothing $199.86 30 3.1 39 BULK-f057ed6d
16393 Bulk Product fd6ca68f Toys & Games $791.05 472 3.8 82 BULK-49f731f2
16394 Bulk Product d2f1b4f1 Sports & Outdoors $758.58 183 2.7 60 BULK-7ae8f2b8
16395 Bulk Product 9817d0b1 Books $110.95 435 3.2 6 BULK-1a063d5b
16396 Bulk Product fec1544d Toys & Games $424.27 291 0.0 75 BULK-527202bd
16397 Bulk Product 91591d8a Home & Garden $984.39 420 4.3 71 BULK-3ffba631
16398 Bulk Product 16434601 Home & Garden $148.81 439 3.3 19 BULK-ce718b1e
16399 Bulk Product 3ca788c1 Sports & Outdoors $361.32 196 4.9 46 BULK-94be404d
16400 Bulk Product 01bd31ff Books $402.44 60 3.1 86 BULK-2684c1f3
16401 Bulk Product 0c34c6bd Clothing $889.89 265 3.2 62 BULK-a4b2864b
16402 Bulk Product 04e113b2 Sports & Outdoors $747.64 125 3.6 25 BULK-018cbf62
16403 Bulk Product 90cd6557 Toys & Games $656.64 3 0.9 41 BULK-be5ca25d
16404 Bulk Product 3dbbe875 Home & Garden $329.12 480 4.7 83 BULK-2b568b63
16405 Bulk Product 9788f6fe Toys & Games $709.71 460 3.1 64 BULK-72224e94
16406 Bulk Product 58ef24fd Sports & Outdoors $190.01 400 2.2 80 BULK-2aeaaeb5
16407 Bulk Product 902efef4 Toys & Games $669.65 331 4.1 7 BULK-c96acfb2
16408 Bulk Product 34a8df22 Books $793.89 276 1.4 83 BULK-05f94826
16409 Bulk Product d966d817 Clothing $216.19 157 2.8 29 BULK-fbae7877
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