Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

947 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 947 Results Showing 23651 - 23675 of 24441

ID Name Category Price Stock Rating Reviews SKU
24210 Bulk Product e3c3ce0a Home & Garden $329.50 458 0.9 36 BULK-c79c9cbf
24211 Bulk Product 819e72ed Toys & Games $312.94 216 4.0 17 BULK-df522470
24212 Bulk Product 2ad6eb58 Electronics $469.64 237 4.1 95 BULK-c39688ad
24213 Bulk Product 3f2a3787 Home & Garden $505.28 427 2.1 0 BULK-4fa2f577
24214 Bulk Product f0e31fc4 Clothing $620.44 139 2.7 77 BULK-d6e1e090
24215 Bulk Product 5becce53 Books $676.60 68 0.5 2 BULK-dcd74fef
24216 Bulk Product 565d3622 Toys & Games $902.60 219 2.8 44 BULK-4eb0671b
24217 Bulk Product cec24dd4 Electronics $844.11 90 4.0 27 BULK-0b1a587b
24218 Bulk Product 0ccf6a3c Clothing $444.30 87 4.4 1 BULK-86f40566
24219 Bulk Product 6675588f Sports & Outdoors $373.78 233 3.8 59 BULK-d652ed94
24220 Bulk Product 70bca328 Sports & Outdoors $820.04 429 4.4 82 BULK-19cb1a26
24221 Bulk Product 47a29a9e Clothing $275.53 95 1.8 17 BULK-169267e7
24222 Bulk Product 94324a0f Sports & Outdoors $173.32 181 0.1 27 BULK-3e4f29f1
24223 Bulk Product 09fd478c Sports & Outdoors $298.01 320 0.7 28 BULK-92b35193
24224 Bulk Product 1a3d44fc Electronics $556.00 129 4.2 88 BULK-01e77511
24225 Bulk Product 5f27a8c1 Sports & Outdoors $447.09 361 0.6 76 BULK-273cef03
24226 Bulk Product a00fc693 Electronics $951.43 498 1.3 98 BULK-07bece2d
24227 Bulk Product 786fbaf8 Clothing $405.38 295 4.8 39 BULK-d3b538cb
24228 Bulk Product 13135d02 Electronics $883.83 162 2.9 45 BULK-3682eaf6
24229 Bulk Product 83020007 Clothing $330.81 409 2.1 11 BULK-4f9939f7
24230 Bulk Product 998be65e Books $922.88 21 2.5 74 BULK-c065e828
24231 Bulk Product 4b7d756c Electronics $561.47 214 1.1 41 BULK-fb9bdecd
24232 Bulk Product 5eff88d5 Sports & Outdoors $218.11 10 2.6 35 BULK-8d00028d
24233 Bulk Product 73d1d22d Home & Garden $380.66 475 4.0 55 BULK-9bc232ed
24234 Bulk Product e248264c Toys & Games $941.26 62 3.7 88 BULK-f6ab70d2
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