Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

80 ms

Page Size

25

Current Page

431 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 431 Results Showing 10751 - 10775 of 24441

ID Name Category Price Stock Rating Reviews SKU
11310 Bulk Product 832967c4 Home & Garden $781.34 245 3.5 89 BULK-83f5ed51
11311 Bulk Product a18d6735 Toys & Games $313.82 88 2.2 10 BULK-e5c59de0
11312 Bulk Product 5f2cd752 Books $423.36 234 2.3 12 BULK-db3fa52f
11313 Bulk Product f24a1385 Toys & Games $918.60 287 1.5 8 BULK-e01e5a41
11314 Bulk Product 2cc67022 Toys & Games $692.11 78 4.8 24 BULK-0700091a
11315 Bulk Product d405d1c4 Sports & Outdoors $475.80 323 4.0 16 BULK-2af8b1f3
11316 Bulk Product bb3c6805 Clothing $341.44 53 0.1 2 BULK-7f7a6d40
11317 Bulk Product 82375a34 Electronics $289.55 318 1.6 0 BULK-7c70bd25
11318 Bulk Product 6503d061 Electronics $831.24 419 2.1 38 BULK-2e15a802
11319 Bulk Product 4ac16aac Toys & Games $252.70 354 4.7 88 BULK-ee50a3c8
11320 Bulk Product 802798a7 Toys & Games $50.47 190 1.6 90 BULK-c6083ef1
11321 Bulk Product 30ef063d Home & Garden $211.69 393 3.5 10 BULK-c7121630
11322 Bulk Product fd427c55 Clothing $588.62 331 4.9 36 BULK-7ac09b3a
11323 Bulk Product c6b3a92b Books $557.44 112 2.3 26 BULK-936c8709
11324 Bulk Product 7c7169ad Clothing $704.44 316 0.3 67 BULK-0923cc86
11325 Bulk Product 5643b501 Electronics $428.89 285 0.1 64 BULK-52cb71c5
11326 Bulk Product fcdb4c8b Electronics $949.25 147 0.2 10 BULK-647399d2
11327 Bulk Product 5ce49caf Clothing $726.98 439 0.2 95 BULK-5c88f96d
11328 Bulk Product a3879473 Electronics $355.72 476 0.5 65 BULK-07af0a70
11329 Bulk Product 8df816ae Home & Garden $169.48 284 3.3 34 BULK-e753e1d7
11330 Bulk Product 6ebbc03a Toys & Games $681.33 94 5.0 42 BULK-5ff6656a
11331 Bulk Product ca59c3f1 Clothing $43.30 271 0.6 27 BULK-c8daaef6
11332 Bulk Product 14508a6c Toys & Games $791.13 375 4.3 62 BULK-31429ddd
11333 Bulk Product 01ce5b11 Clothing $875.03 223 1.3 40 BULK-f80e1223
11334 Bulk Product 0150713e Books $867.80 118 2.0 80 BULK-47d736e9
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