Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

538 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 538 Results Showing 13426 - 13450 of 24441

ID Name Category Price Stock Rating Reviews SKU
13985 Bulk Product b99c904a Clothing $123.88 218 0.5 68 BULK-976debcb
13986 Bulk Product f9159494 Toys & Games $360.32 60 0.7 41 BULK-490b6761
13987 Bulk Product 9af57427 Electronics $893.72 373 2.9 83 BULK-ac5f9a3f
13988 Bulk Product 6bf9f954 Toys & Games $548.98 254 1.4 93 BULK-ff51205e
13989 Bulk Product e955e69f Home & Garden $516.49 433 3.9 91 BULK-724e1ebc
13990 Bulk Product 039aa82f Home & Garden $923.14 380 1.9 34 BULK-62b52410
13991 Bulk Product 4779cf93 Sports & Outdoors $789.98 35 4.0 2 BULK-1a4818a7
13992 Bulk Product ab14eba4 Toys & Games $160.97 313 0.3 75 BULK-9ed29635
13993 Bulk Product 87758823 Home & Garden $843.07 103 3.8 74 BULK-8d0c8503
13994 Bulk Product 86ce161f Sports & Outdoors $403.08 65 2.0 59 BULK-605cdf95
13995 Bulk Product 81528506 Electronics $171.39 200 2.4 55 BULK-2947f204
13996 Bulk Product 47f5b14a Books $90.83 266 2.7 3 BULK-8bf66052
13997 Bulk Product 91302a8d Home & Garden $433.78 147 4.2 29 BULK-9fdb874e
13998 Bulk Product ace17c91 Home & Garden $683.36 366 2.7 5 BULK-55c0eaa5
13999 Bulk Product ae3d4be9 Clothing $521.47 4 4.6 5 BULK-9d3abc8e
14000 Bulk Product 4bd55dc3 Home & Garden $437.98 98 3.0 63 BULK-46ee42ab
14001 Bulk Product 2ac8644e Toys & Games $810.79 340 3.0 33 BULK-28635b5b
14002 Bulk Product ca61e9d8 Books $115.83 156 1.3 11 BULK-1360136b
14003 Bulk Product 3a045b13 Home & Garden $467.13 22 4.8 23 BULK-fa9cdf1e
14004 Bulk Product 5cd9ec55 Clothing $465.10 78 2.3 11 BULK-26f37e17
14005 Bulk Product bb082710 Electronics $771.76 396 2.6 41 BULK-6cd60cf3
14006 Bulk Product bd4816f2 Sports & Outdoors $392.46 61 4.1 22 BULK-07a172ea
14007 Bulk Product 00e0469d Toys & Games $883.55 382 2.3 44 BULK-2b7ecd25
14008 Bulk Product ccc4c307 Clothing $17.69 342 3.2 12 BULK-dc8ba29b
14009 Bulk Product c43e4138 Toys & Games $869.64 64 0.5 94 BULK-ab50a8f8
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