Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

251 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 251 Results Showing 6251 - 6275 of 24441

ID Name Category Price Stock Rating Reviews SKU
6810 Bulk Product edd9cd32 Books $806.62 145 3.2 94 BULK-986ddd8d
6811 Bulk Product 22076098 Clothing $683.62 407 1.6 70 BULK-29411cd3
6812 Bulk Product 119f77f0 Clothing $477.76 232 0.5 14 BULK-f73501a0
6813 Bulk Product 2043a800 Sports & Outdoors $193.14 241 1.7 82 BULK-b615a69e
6814 Bulk Product cf3fe8de Books $384.30 421 4.4 86 BULK-a287d026
6815 Bulk Product 8629c276 Home & Garden $585.26 362 0.7 39 BULK-85d99a03
6816 Bulk Product 4ffedbc7 Toys & Games $107.47 360 3.7 92 BULK-cfb24d0f
6817 Bulk Product 7024d887 Sports & Outdoors $816.68 348 2.5 52 BULK-a6e3e53f
6818 Bulk Product 006a0b98 Sports & Outdoors $101.05 164 0.3 17 BULK-289807ec
6819 Bulk Product d19fd3e0 Home & Garden $872.86 32 2.5 26 BULK-cae86967
6820 Bulk Product e4b91178 Books $435.11 376 2.2 76 BULK-44f8999e
6821 Bulk Product 0830e3ea Sports & Outdoors $784.39 484 3.1 71 BULK-4170fa41
6822 Bulk Product c7af291c Clothing $122.01 308 2.8 88 BULK-eb85fd93
6823 Bulk Product 809399fa Home & Garden $830.57 203 3.0 45 BULK-770c1ab2
6824 Bulk Product cfefa471 Toys & Games $656.70 115 2.2 17 BULK-90776875
6825 Bulk Product 1f9dad43 Clothing $865.43 308 0.0 13 BULK-d9d20da1
6826 Bulk Product 2500c724 Electronics $981.15 325 3.3 16 BULK-261c10cf
6827 Bulk Product 743c3c11 Toys & Games $961.14 440 4.9 27 BULK-03171187
6828 Bulk Product ee4f2dcc Sports & Outdoors $665.34 95 0.2 51 BULK-8bfb55bd
6829 Bulk Product a2b9abbd Home & Garden $999.68 169 0.9 43 BULK-ba9ea684
6830 Bulk Product 79e8a712 Toys & Games $852.87 191 2.0 84 BULK-663f5b5d
6831 Bulk Product 98696a9a Electronics $432.98 268 4.6 85 BULK-b7d4f86f
6832 Bulk Product d266de72 Clothing $27.16 348 1.4 30 BULK-6ffd6c75
6833 Bulk Product 726aa53d Books $991.51 487 4.4 9 BULK-d8bc9d70
6834 Bulk Product c22cbfd4 Electronics $288.08 168 3.9 9 BULK-9bb93069
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