Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

231 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 231 Results Showing 5751 - 5775 of 24441

ID Name Category Price Stock Rating Reviews SKU
6310 Bulk Product 5a932a52 Books $293.09 156 1.1 68 BULK-44727ac6
6311 Bulk Product e8efc20b Toys & Games $722.87 169 4.7 56 BULK-6b806975
6312 Bulk Product c0c15a46 Books $902.00 55 2.6 39 BULK-8c2aefba
6313 Bulk Product 041c6f81 Home & Garden $811.23 395 0.8 76 BULK-44c1195d
6314 Bulk Product 56eff477 Clothing $122.33 67 2.0 36 BULK-b2d9957b
6315 Bulk Product 4f072026 Home & Garden $979.37 442 2.8 41 BULK-d053d0a8
6316 Bulk Product 21bef580 Toys & Games $699.34 427 2.9 16 BULK-a0f772d0
6317 Bulk Product e9d01d09 Sports & Outdoors $949.40 481 3.4 40 BULK-c8ad7aab
6318 Bulk Product 8a0cd6f0 Toys & Games $517.86 324 4.3 22 BULK-948f8697
6319 Bulk Product 757f738e Electronics $866.33 295 1.4 66 BULK-249c311d
6320 Bulk Product 90209e1b Clothing $741.33 320 3.9 1 BULK-92b8e1ef
6321 Bulk Product eb2306b1 Home & Garden $794.56 140 4.6 93 BULK-d0b669d8
6322 Bulk Product 58d4a15a Clothing $811.93 56 2.8 27 BULK-616ecbb2
6323 Bulk Product aa10c91d Clothing $134.53 476 1.8 36 BULK-1a83e3c7
6324 Bulk Product 536c9c73 Toys & Games $410.59 241 4.0 25 BULK-382c53a3
6325 Bulk Product 56457042 Clothing $879.04 62 3.6 88 BULK-7d965df2
6326 Bulk Product 59e53a50 Sports & Outdoors $255.30 311 2.8 76 BULK-0ed44500
6327 Bulk Product 797bd272 Clothing $217.79 188 2.4 98 BULK-629b7487
6328 Bulk Product 46701da6 Home & Garden $298.48 99 3.9 89 BULK-c93d183e
6329 Bulk Product ce269d2b Sports & Outdoors $249.84 411 4.0 14 BULK-88789bf3
6330 Bulk Product 35d61396 Sports & Outdoors $897.45 116 1.8 47 BULK-ae18cb89
6331 Bulk Product 56aa2df1 Sports & Outdoors $791.84 498 1.3 52 BULK-e06f9b94
6332 Bulk Product ff4795ee Clothing $929.17 330 0.1 24 BULK-1296fcde
6333 Bulk Product de4c4ab9 Books $813.53 96 2.4 26 BULK-c8248706
6334 Bulk Product 39ae6169 Books $850.09 129 1.7 19 BULK-e3a853a3
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