Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

357 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 357 Results Showing 8901 - 8925 of 24441

ID Name Category Price Stock Rating Reviews SKU
9460 Bulk Product 3acee5c7 Electronics $696.97 257 2.1 10 BULK-85cb3297
9461 Bulk Product d8e1b830 Electronics $1,000.82 449 0.8 6 BULK-13e2c072
9462 Bulk Product d17c44e8 Clothing $123.12 122 3.2 57 BULK-b23694fe
9463 Bulk Product 76a9f7d8 Books $757.84 340 0.1 99 BULK-f4e232ae
9464 Bulk Product 550460ab Sports & Outdoors $996.46 321 0.7 54 BULK-806a13ac
9465 Bulk Product 6fb27b19 Electronics $399.97 50 4.6 6 BULK-58451bf3
9466 Bulk Product 6921afc6 Home & Garden $750.64 53 3.8 39 BULK-f489f6a7
9467 Bulk Product 59aba3b1 Books $198.04 104 2.7 51 BULK-69d5c971
9468 Bulk Product b0f1169a Books $581.12 160 4.4 72 BULK-171c0487
9469 Bulk Product 6871dc8f Electronics $338.31 154 2.3 83 BULK-a17eb617
9470 Bulk Product 8a2b3d88 Electronics $83.09 418 3.6 25 BULK-b51facb1
9471 Bulk Product 9030ff95 Books $70.62 203 3.5 79 BULK-20535874
9472 Bulk Product 54b2ed66 Home & Garden $322.79 320 2.4 31 BULK-8ce6332f
9473 Bulk Product 3b89d2cf Sports & Outdoors $209.54 265 1.6 95 BULK-79d2ce3e
9474 Bulk Product 51ddbee3 Home & Garden $349.37 63 2.7 42 BULK-3ffceea7
9475 Bulk Product 716fa5cd Toys & Games $549.73 308 3.6 78 BULK-503dd00e
9476 Bulk Product 84e87f52 Books $375.45 296 5.0 75 BULK-4a015ade
9477 Bulk Product 60c64108 Toys & Games $332.45 296 1.5 81 BULK-e06b6617
9478 Bulk Product acb5c6c2 Sports & Outdoors $977.36 325 3.1 50 BULK-eeb1143d
9479 Bulk Product 80746a26 Clothing $401.51 405 4.2 9 BULK-7a84ff8f
9480 Bulk Product 701a4698 Clothing $850.98 210 3.7 50 BULK-5a2e3df8
9481 Bulk Product 7dff0f9b Clothing $309.99 52 0.6 43 BULK-eb1116d6
9482 Bulk Product 8526b9c5 Electronics $346.37 34 1.1 53 BULK-a773b485
9483 Bulk Product 77c215ca Clothing $149.00 220 3.7 69 BULK-6156aca0
9484 Bulk Product f1320299 Electronics $29.98 22 4.7 6 BULK-a9d91f5b
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