Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

542 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 542 Results Showing 13526 - 13550 of 24441

ID Name Category Price Stock Rating Reviews SKU
14085 Bulk Product 8afb1593 Clothing $645.33 413 1.1 86 BULK-4459a322
14086 Bulk Product 15d9dba4 Sports & Outdoors $857.50 355 3.9 36 BULK-801caa06
14087 Bulk Product 0263fd25 Books $580.32 55 3.9 88 BULK-5762be17
14088 Bulk Product 766ed5c6 Home & Garden $298.67 104 2.7 45 BULK-99fcecf3
14089 Bulk Product 103101ff Electronics $423.17 332 3.4 63 BULK-c01ab177
14090 Bulk Product f1dba101 Clothing $149.65 171 1.0 35 BULK-41dc1524
14091 Bulk Product 8d145534 Sports & Outdoors $110.15 233 4.9 93 BULK-e8838594
14092 Bulk Product f41a1538 Toys & Games $398.87 286 3.2 77 BULK-5e2cb806
14093 Bulk Product 7fea3520 Sports & Outdoors $851.89 65 0.6 46 BULK-74540be4
14094 Bulk Product 9482a794 Clothing $721.27 57 2.1 44 BULK-5601f8b8
14095 Bulk Product 06119eb7 Clothing $991.97 71 0.4 30 BULK-36b3ba7d
14096 Bulk Product f017be9c Home & Garden $788.73 77 3.7 71 BULK-4d3179df
14097 Bulk Product e951c96a Home & Garden $825.15 406 4.6 59 BULK-ee32bc99
14098 Bulk Product 05dde0cf Sports & Outdoors $260.95 81 3.3 30 BULK-371646f8
14099 Bulk Product 7044057e Toys & Games $274.68 431 3.2 36 BULK-66618630
14100 Bulk Product 021acd30 Sports & Outdoors $253.84 431 0.5 52 BULK-2bb5e245
14101 Bulk Product 2fe7b0a1 Clothing $860.33 385 0.7 3 BULK-2571a335
14102 Bulk Product a87e6c8e Sports & Outdoors $954.60 336 1.9 16 BULK-294ce328
14103 Bulk Product 3a609261 Home & Garden $487.46 262 4.2 37 BULK-e83a36d2
14104 Bulk Product 65d09bdb Electronics $358.26 227 2.2 81 BULK-7cef017e
14105 Bulk Product 04c3b8b8 Electronics $648.51 105 0.3 84 BULK-a7a7053e
14106 Bulk Product 78f04e46 Sports & Outdoors $350.18 216 4.4 94 BULK-4a52d7c4
14107 Bulk Product d9b595d1 Toys & Games $264.77 489 3.9 23 BULK-29264cda
14108 Bulk Product 524cbe8d Home & Garden $384.44 411 4.2 4 BULK-38e748e1
14109 Bulk Product 65040edc Toys & Games $846.27 220 1.6 75 BULK-57bb0eaf
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