Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

267 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 267 Results Showing 6651 - 6675 of 24441

ID Name Category Price Stock Rating Reviews SKU
7210 Bulk Product 6ea441a4 Toys & Games $678.49 459 3.6 14 BULK-a8071843
7211 Bulk Product 67a7f51a Clothing $529.04 281 4.5 96 BULK-898a324f
7212 Bulk Product 63d2b484 Sports & Outdoors $999.59 132 2.0 63 BULK-faa25a33
7213 Bulk Product 4efc919e Sports & Outdoors $577.74 106 0.3 14 BULK-339d3f9c
7214 Bulk Product 515df6be Home & Garden $69.98 376 4.6 79 BULK-0556d483
7215 Bulk Product 67c98e5f Books $614.54 477 2.0 29 BULK-9deae44a
7216 Bulk Product 7f32b2b9 Clothing $227.51 423 2.5 91 BULK-9c3e9efb
7217 Bulk Product fd5eb6f5 Home & Garden $524.87 317 0.1 8 BULK-abfa513a
7218 Bulk Product d627089c Home & Garden $314.38 284 2.9 18 BULK-62bc1e93
7219 Bulk Product 62d28b13 Toys & Games $347.36 27 4.4 81 BULK-91aca275
7220 Bulk Product 5dc07a5c Electronics $218.94 298 2.6 97 BULK-fb29a91a
7221 Bulk Product 9101c0b8 Toys & Games $625.12 24 0.6 53 BULK-1a7c70de
7222 Bulk Product 4da6cc14 Books $110.56 327 4.9 79 BULK-56e2c569
7223 Bulk Product 231f1333 Home & Garden $22.53 164 2.8 2 BULK-2b2f4417
7224 Bulk Product fe7d7aee Electronics $971.78 143 2.7 84 BULK-9870311f
7225 Bulk Product e533ffee Sports & Outdoors $112.77 313 0.2 2 BULK-dbe04627
7226 Bulk Product 2fad2460 Home & Garden $190.89 402 4.9 61 BULK-4a41c9fa
7227 Bulk Product ae580296 Home & Garden $551.22 233 0.1 5 BULK-f3b127f7
7228 Bulk Product 55f51f1c Electronics $806.99 120 1.1 29 BULK-b854f7a6
7229 Bulk Product 9e2a6623 Books $601.73 44 0.1 73 BULK-4ecdc706
7230 Bulk Product fa6179b3 Home & Garden $524.24 216 4.2 55 BULK-badbc189
7231 Bulk Product 8e6d1f0d Clothing $414.74 325 3.9 85 BULK-29ced2e1
7232 Bulk Product 2853ea54 Electronics $966.76 490 1.6 77 BULK-c1607561
7233 Bulk Product 0273f0e2 Toys & Games $517.83 338 4.7 34 BULK-c61a2836
7234 Bulk Product 7fc32fa8 Clothing $296.09 302 1.1 27 BULK-832c4a86
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