Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

768 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 768 Results Showing 19176 - 19200 of 24441

ID Name Category Price Stock Rating Reviews SKU
19735 Bulk Product 43d193d9 Sports & Outdoors $799.61 368 1.1 85 BULK-6cc7929b
19736 Bulk Product de296a45 Electronics $541.69 29 4.3 56 BULK-4bebf677
19737 Bulk Product 1c54878d Home & Garden $62.51 88 1.3 28 BULK-d052078c
19738 Bulk Product 302d340f Books $296.81 260 0.8 8 BULK-f78f1a87
19739 Bulk Product 8e35dfe6 Books $949.20 114 1.1 48 BULK-49d5dabc
19740 Bulk Product fbae1b45 Home & Garden $900.57 310 3.0 83 BULK-305156ec
19741 Bulk Product 4338ca05 Books $280.66 148 4.7 8 BULK-30e238e9
19742 Bulk Product d9b2ab0e Books $635.74 323 0.7 3 BULK-de3fccfa
19743 Bulk Product 0b1a5d94 Toys & Games $389.71 473 3.2 51 BULK-286c94e0
19744 Bulk Product 669707b3 Clothing $727.18 220 1.3 59 BULK-91493b0e
19745 Bulk Product ce7d9179 Home & Garden $99.11 327 4.2 76 BULK-c1d7a408
19746 Bulk Product 07d20c70 Books $676.07 221 1.4 41 BULK-06f18981
19747 Bulk Product 3c2f100c Electronics $887.31 89 4.1 84 BULK-bc01e5dc
19748 Bulk Product 86356f58 Home & Garden $892.73 364 4.3 97 BULK-089bd851
19749 Bulk Product 38b8c4e4 Electronics $727.45 202 4.1 31 BULK-a82abd1c
19750 Bulk Product b391c70d Clothing $902.62 46 4.4 6 BULK-48cc8b61
19751 Bulk Product ae14e948 Sports & Outdoors $451.21 81 2.8 54 BULK-80993e45
19752 Bulk Product 574e25d4 Home & Garden $830.73 216 3.3 5 BULK-c565d62d
19753 Bulk Product 20f773ec Toys & Games $914.25 458 0.7 16 BULK-3aa996bb
19754 Bulk Product d0e21743 Books $41.62 364 1.6 32 BULK-138e3ccb
19755 Bulk Product f941b99a Home & Garden $536.25 46 4.8 5 BULK-12f9e1f2
19756 Bulk Product 25601e31 Home & Garden $165.29 83 0.9 9 BULK-dc04ae8a
19757 Bulk Product 4edf82a0 Clothing $712.15 17 2.2 56 BULK-a4c89253
19758 Bulk Product 8275a28d Clothing $228.44 255 1.8 71 BULK-7f5e69cb
19759 Bulk Product db90c53f Electronics $347.78 10 1.8 14 BULK-8c2ae201
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