Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

937 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 937 Results Showing 23401 - 23425 of 24441

ID Name Category Price Stock Rating Reviews SKU
23960 Bulk Product 5ab1f1ef Electronics $139.49 426 4.6 89 BULK-71d1d6db
23961 Bulk Product 264db5db Clothing $20.11 195 1.3 95 BULK-7beaf9fd
23962 Bulk Product 9e6efabd Electronics $614.54 259 4.8 97 BULK-7bfc35d5
23963 Bulk Product fe5467bb Home & Garden $959.72 248 4.5 48 BULK-86fa1f75
23964 Bulk Product e168e185 Sports & Outdoors $834.28 424 3.8 90 BULK-a5b2d3bb
23965 Bulk Product f1d9a602 Clothing $295.73 478 4.7 29 BULK-826779f2
23966 Bulk Product f655bd18 Sports & Outdoors $353.22 315 3.9 64 BULK-e91daafa
23967 Bulk Product a4aa5efc Sports & Outdoors $582.16 351 4.6 65 BULK-51eac99d
23968 Bulk Product 90d93753 Toys & Games $264.79 353 2.6 64 BULK-0cdd6e33
23969 Bulk Product 7a5297a4 Electronics $960.04 402 0.9 39 BULK-14ed8c90
23970 Bulk Product 63104089 Home & Garden $696.65 366 4.4 66 BULK-4efb8593
23971 Bulk Product 0b379b36 Toys & Games $300.60 285 1.4 47 BULK-c627a0d3
23972 Bulk Product 875288c9 Electronics $101.80 406 3.1 43 BULK-e79af72c
23973 Bulk Product 68ea479d Books $722.19 312 4.9 85 BULK-6434dfb7
23974 Bulk Product 8943205c Clothing $818.27 65 4.8 60 BULK-9f10e59d
23975 Bulk Product d1c87362 Sports & Outdoors $175.78 207 0.9 22 BULK-8fe590d7
23976 Bulk Product dec90429 Electronics $767.65 384 2.9 45 BULK-d7883a61
23977 Bulk Product 3e375676 Books $578.97 188 1.4 79 BULK-99096fe4
23978 Bulk Product 91073935 Sports & Outdoors $226.55 164 0.5 18 BULK-84b40169
23979 Bulk Product b49772a5 Toys & Games $27.62 16 4.3 24 BULK-b4986a3c
23980 Bulk Product fd92d8a5 Electronics $216.57 487 3.8 96 BULK-267c5540
23981 Bulk Product 0ed44583 Books $803.99 148 0.7 86 BULK-71e9da9b
23982 Bulk Product e89bd564 Home & Garden $69.29 187 4.7 95 BULK-0b671936
23983 Bulk Product 1b34636c Electronics $496.61 157 2.9 88 BULK-c1b3ba96
23984 Bulk Product 0e4f0668 Electronics $420.58 476 3.2 59 BULK-7aa19426
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