Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

476 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 476 Results Showing 11876 - 11900 of 24441

ID Name Category Price Stock Rating Reviews SKU
12435 Bulk Product 8a57fac4 Toys & Games $93.85 378 4.0 69 BULK-a0dadd5a
12436 Bulk Product d1fb0abe Clothing $779.89 97 0.2 79 BULK-a700281d
12437 Bulk Product 1546cb79 Home & Garden $993.59 88 1.3 26 BULK-7d3bc508
12438 Bulk Product 14202302 Clothing $806.33 460 1.1 59 BULK-294b6177
12439 Bulk Product b2fbc054 Home & Garden $1,004.40 173 2.1 22 BULK-a752972f
12440 Bulk Product 9d92d8c4 Electronics $518.68 199 3.7 58 BULK-3a819b6f
12441 Bulk Product 08d6c19c Electronics $335.55 108 4.7 19 BULK-17af22c1
12442 Bulk Product cf92b22c Books $161.35 300 1.6 0 BULK-d5af1796
12443 Bulk Product a69c3acb Sports & Outdoors $264.45 71 3.0 95 BULK-ac92524c
12444 Bulk Product 839970c5 Books $173.70 342 4.2 69 BULK-2e979ca5
12445 Bulk Product 37cd9cbd Clothing $448.50 83 4.4 57 BULK-9cb06917
12446 Bulk Product a96058cf Home & Garden $84.51 270 0.7 77 BULK-e587a5a1
12447 Bulk Product 1b49da2b Toys & Games $289.16 258 4.8 63 BULK-4ceddc1e
12448 Bulk Product 25e8472d Toys & Games $290.38 400 2.2 2 BULK-84c3e9cc
12449 Bulk Product f4adefd7 Electronics $463.80 249 1.5 71 BULK-d81e1234
12450 Bulk Product 6d2281f1 Sports & Outdoors $578.23 22 1.5 0 BULK-4bdda6b3
12451 Bulk Product cfcfbe8f Books $516.92 179 3.8 38 BULK-15c8ed34
12452 Bulk Product 9f1b24bc Home & Garden $150.11 221 4.4 24 BULK-3f10e040
12453 Bulk Product fa281a0e Electronics $339.15 287 0.0 7 BULK-f04987fa
12454 Bulk Product 46de9237 Toys & Games $335.55 179 0.0 27 BULK-d6c174d8
12455 Bulk Product 9f7c0212 Sports & Outdoors $228.25 232 4.5 54 BULK-ddcecb9f
12456 Bulk Product 595aa3c5 Electronics $353.95 266 3.1 39 BULK-69fa003b
12457 Bulk Product 35fba609 Sports & Outdoors $834.68 7 1.6 84 BULK-e66b51a5
12458 Bulk Product 98e53ae8 Clothing $739.58 151 4.2 8 BULK-03722eff
12459 Bulk Product c81fa1b4 Toys & Games $377.32 324 1.1 10 BULK-4134037c
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