Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

870 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 870 Results Showing 21726 - 21750 of 24441

ID Name Category Price Stock Rating Reviews SKU
22285 Bulk Product ea58a66b Books $960.21 441 4.3 46 BULK-6590b78c
22286 Bulk Product 7e90ae22 Toys & Games $920.78 476 1.6 59 BULK-68ce7dd2
22287 Bulk Product 6bae25fa Electronics $291.38 278 3.2 66 BULK-06e19f1e
22288 Bulk Product 9c8c4500 Books $596.52 17 4.5 25 BULK-54fa1a46
22289 Bulk Product 379cdec3 Electronics $886.65 284 2.0 7 BULK-42fda931
22290 Bulk Product 73ec4001 Toys & Games $895.58 190 0.6 27 BULK-d4d81b60
22291 Bulk Product f2116ddf Home & Garden $636.50 461 4.6 42 BULK-4d61a7d3
22292 Bulk Product 1f8b48e7 Home & Garden $450.00 212 2.0 1 BULK-8a8f66fd
22293 Bulk Product 5b7455a2 Electronics $447.65 356 4.5 21 BULK-fd08c0d4
22294 Bulk Product 48354b8f Clothing $579.28 138 4.5 75 BULK-6cfd09ac
22295 Bulk Product baf981a1 Sports & Outdoors $575.61 41 3.3 61 BULK-a9ad5b0c
22296 Bulk Product 4d946dbe Toys & Games $199.99 305 0.4 55 BULK-87690392
22297 Bulk Product 46da0394 Home & Garden $159.69 142 2.8 22 BULK-6be37e6a
22298 Bulk Product e245e609 Toys & Games $251.61 257 2.3 8 BULK-83a3ddbd
22299 Bulk Product 0de37a0b Electronics $255.78 93 0.0 48 BULK-3fd5cdcb
22300 Bulk Product 144d4a2c Toys & Games $322.73 41 3.1 61 BULK-aa4bc9ee
22301 Bulk Product 06ca6dd3 Sports & Outdoors $959.26 148 4.4 90 BULK-61c524db
22302 Bulk Product effa1b80 Home & Garden $407.78 150 0.9 11 BULK-f0fb99f7
22303 Bulk Product b6281986 Clothing $583.26 253 3.1 88 BULK-61fec204
22304 Bulk Product 499ef9c1 Toys & Games $941.32 8 1.8 76 BULK-99a5fef6
22305 Bulk Product 03e4c7c1 Clothing $273.47 164 2.6 8 BULK-f1836fea
22306 Bulk Product b282f66b Books $956.21 64 0.1 26 BULK-39b0a310
22307 Bulk Product a583ad9a Home & Garden $768.68 263 1.0 6 BULK-bd655d31
22308 Bulk Product 81cba144 Clothing $462.05 492 3.5 23 BULK-6978ca22
22309 Bulk Product 90de8140 Electronics $769.74 297 0.8 15 BULK-b3d7fe41
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