Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

60 ms

Page Size

25

Current Page

868 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 868 Results Showing 21676 - 21700 of 24441

ID Name Category Price Stock Rating Reviews SKU
22235 Bulk Product 3b0fee44 Clothing $11.95 99 1.4 79 BULK-474fc4c2
22236 Bulk Product b28171cd Sports & Outdoors $237.64 393 4.6 11 BULK-51722f16
22237 Bulk Product cfe6f499 Electronics $940.38 389 0.4 14 BULK-770e22aa
22238 Bulk Product c4b0aa0e Electronics $62.54 16 1.8 63 BULK-35e7a6bd
22239 Bulk Product e6e8f77e Books $941.00 300 0.8 48 BULK-6373a499
22240 Bulk Product 1e1543a7 Toys & Games $312.26 158 0.4 78 BULK-e2c04a61
22241 Bulk Product fd781678 Electronics $868.44 62 1.6 55 BULK-686893cc
22242 Bulk Product ddbcc9d7 Toys & Games $45.71 449 0.6 65 BULK-f3150e7c
22243 Bulk Product b1208421 Clothing $627.37 477 1.0 67 BULK-991b5d4f
22244 Bulk Product a6ec570b Books $787.40 273 2.5 24 BULK-a190b596
22245 Bulk Product 87139dd5 Clothing $514.94 53 1.7 25 BULK-34ceab3c
22246 Bulk Product fab7fbf4 Home & Garden $157.64 348 4.9 42 BULK-d415dea9
22247 Bulk Product f81cfe68 Electronics $658.08 395 4.8 18 BULK-f02673a1
22248 Bulk Product 6e0a1359 Toys & Games $264.30 247 1.8 26 BULK-8dd84ffc
22249 Bulk Product 3feba4b4 Clothing $279.96 278 0.8 82 BULK-bd4a5043
22250 Bulk Product 52a722b5 Clothing $1,000.84 161 1.8 3 BULK-2c1df815
22251 Bulk Product 53c3fcfe Sports & Outdoors $437.10 477 0.6 23 BULK-305f0d5d
22252 Bulk Product 632a5852 Home & Garden $934.23 277 4.9 68 BULK-fe64ffde
22253 Bulk Product 83787ee0 Home & Garden $248.09 436 1.0 14 BULK-e921eb68
22254 Bulk Product 1048f571 Sports & Outdoors $126.44 323 1.2 25 BULK-bb718965
22255 Bulk Product 6dd4a6a2 Sports & Outdoors $76.37 455 1.6 65 BULK-ad7d7896
22256 Bulk Product 28782f94 Toys & Games $802.97 242 1.3 72 BULK-2f012ddb
22257 Bulk Product fae75225 Sports & Outdoors $956.17 93 2.9 19 BULK-f8792116
22258 Bulk Product 763ec35e Home & Garden $836.03 95 4.5 6 BULK-37430572
22259 Bulk Product def92573 Electronics $956.04 16 1.4 52 BULK-59ed5e50
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