Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

926 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 926 Results Showing 23126 - 23150 of 24441

ID Name Category Price Stock Rating Reviews SKU
23685 Bulk Product 62414df9 Sports & Outdoors $295.48 347 4.7 26 BULK-1be6ee5d
23686 Bulk Product 432cd0fd Electronics $979.04 122 1.8 7 BULK-cbe88c8b
23687 Bulk Product bad3b76e Books $905.11 296 3.6 45 BULK-f606480d
23688 Bulk Product a1dfa2bc Books $450.41 41 0.7 52 BULK-75363431
23689 Bulk Product 93e560dd Home & Garden $242.24 481 2.5 2 BULK-bd635da1
23690 Bulk Product a26ecc97 Sports & Outdoors $710.42 61 0.3 67 BULK-826a445c
23691 Bulk Product 28db3076 Toys & Games $318.96 452 3.8 83 BULK-1e1703e3
23692 Bulk Product bd8d0953 Electronics $690.73 269 0.8 17 BULK-76925003
23693 Bulk Product 9968dbfb Toys & Games $135.83 48 1.0 47 BULK-924a08cc
23694 Bulk Product 17cee009 Clothing $184.27 325 1.8 74 BULK-8a786794
23695 Bulk Product 8c64d46b Toys & Games $783.39 164 1.3 54 BULK-3e8d15c8
23696 Bulk Product 81464c69 Home & Garden $792.17 133 0.9 24 BULK-dcba5ad3
23697 Bulk Product e167ef41 Toys & Games $121.74 289 3.2 67 BULK-be45aafa
23698 Bulk Product e0686779 Toys & Games $74.42 300 4.9 18 BULK-73065c12
23699 Bulk Product b86f0f29 Sports & Outdoors $459.10 327 5.0 61 BULK-e41f03f1
23700 Bulk Product fe0e9deb Toys & Games $223.36 400 0.1 13 BULK-2a2b698e
23701 Bulk Product 3f5a2e86 Toys & Games $515.23 70 3.7 48 BULK-34707e15
23702 Bulk Product 8f6301da Electronics $248.55 4 3.5 41 BULK-fde8ee65
23703 Bulk Product a42df177 Toys & Games $360.63 172 4.9 15 BULK-0e14742e
23704 Bulk Product 8d2581d2 Toys & Games $637.62 176 3.9 78 BULK-49ec2aa8
23705 Bulk Product aad20c8e Toys & Games $385.54 366 4.6 75 BULK-bab475ff
23706 Bulk Product 7c66edb7 Clothing $784.65 117 3.3 74 BULK-d2a5cfc7
23707 Bulk Product e21190e1 Books $800.91 21 4.6 17 BULK-94aa3b78
23708 Bulk Product 504f2e2f Home & Garden $321.88 408 3.9 32 BULK-5116fead
23709 Bulk Product f41f57f0 Sports & Outdoors $98.01 335 3.3 89 BULK-03a11288
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