Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

605 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 605 Results Showing 15101 - 15125 of 24441

ID Name Category Price Stock Rating Reviews SKU
15660 Bulk Product ad7d925f Books $391.44 108 0.6 49 BULK-af6f843e
15661 Bulk Product c173f075 Sports & Outdoors $212.36 285 1.3 83 BULK-33def0d2
15662 Bulk Product 39d43c4d Sports & Outdoors $462.37 220 0.2 60 BULK-1f341833
15663 Bulk Product 11925d7c Electronics $382.02 461 4.8 20 BULK-576a1284
15664 Bulk Product d56bbccb Home & Garden $275.47 413 1.5 91 BULK-bd066fac
15665 Bulk Product 6606d773 Home & Garden $222.92 125 2.5 11 BULK-e25b0695
15666 Bulk Product 90d68e88 Sports & Outdoors $274.90 56 1.8 57 BULK-3aead12a
15667 Bulk Product 6e347fa9 Clothing $978.77 355 0.7 86 BULK-1ed35e8a
15668 Bulk Product 03ca421f Electronics $127.33 124 0.7 8 BULK-3230c3ec
15669 Bulk Product 22daf736 Clothing $917.85 379 2.0 36 BULK-df35debb
15670 Bulk Product 79b74c94 Toys & Games $36.37 267 1.6 81 BULK-1c5b7e75
15671 Bulk Product 584007fd Books $644.29 110 0.7 13 BULK-f6c97a03
15672 Bulk Product a3e577c2 Toys & Games $247.18 50 3.4 46 BULK-68247bce
15673 Bulk Product f87e3fee Toys & Games $777.11 89 0.4 81 BULK-91791c9c
15674 Bulk Product ac15d389 Clothing $419.88 194 0.0 11 BULK-1aa7d440
15675 Bulk Product a30bec7c Electronics $703.93 181 4.1 58 BULK-61288ac2
15676 Bulk Product ce07f2e5 Electronics $587.45 479 3.1 57 BULK-da1e6477
15677 Bulk Product 0159814e Electronics $565.66 76 1.4 14 BULK-ee38fc79
15678 Bulk Product 8b69454c Books $493.20 394 3.9 50 BULK-570a0375
15679 Bulk Product 8e332dc2 Sports & Outdoors $438.13 358 1.0 74 BULK-af5ba799
15680 Bulk Product 6fe72916 Clothing $173.74 5 3.0 59 BULK-988a4880
15681 Bulk Product 2a0c5f59 Books $899.84 213 2.5 98 BULK-b0fb10ba
15682 Bulk Product 5c8c555d Clothing $872.13 413 3.1 55 BULK-e9b607c9
15683 Bulk Product 3d50c3ab Books $909.12 90 2.7 89 BULK-14a8614e
15684 Bulk Product bad78bae Home & Garden $122.49 296 4.6 64 BULK-3e8ff9be
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