Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

31 ms

Page Size

25

Current Page

695 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 695 Results Showing 17351 - 17375 of 24441

ID Name Category Price Stock Rating Reviews SKU
17910 Bulk Product 42c1b962 Books $914.46 114 3.9 22 BULK-03548233
17911 Bulk Product ae4411ec Home & Garden $802.88 151 3.9 75 BULK-9b186370
17912 Bulk Product fab71fa4 Home & Garden $885.88 418 4.2 28 BULK-80ae17f5
17913 Bulk Product b5aa2184 Toys & Games $183.57 210 1.6 91 BULK-08dc316c
17914 Bulk Product 713992bb Electronics $379.39 395 3.5 38 BULK-09cbbc26
17915 Bulk Product 0da5a507 Toys & Games $758.43 173 0.4 0 BULK-117e45c1
17916 Bulk Product 8e214542 Clothing $712.90 44 0.8 85 BULK-f4c445c2
17917 Bulk Product f472e186 Sports & Outdoors $163.32 493 2.9 84 BULK-44a4decf
17918 Bulk Product a1b59445 Sports & Outdoors $111.98 254 0.7 99 BULK-1657a2db
17919 Bulk Product b5d81fb7 Electronics $782.80 392 3.4 40 BULK-8db53c80
17920 Bulk Product a09b3dc3 Books $299.93 307 4.2 31 BULK-86ce77c0
17921 Bulk Product f342abf2 Home & Garden $664.84 335 4.6 7 BULK-d44cfdec
17922 Bulk Product 73fc3bd8 Sports & Outdoors $812.05 468 3.1 47 BULK-86e36b82
17923 Bulk Product 654edec3 Books $646.47 210 0.4 46 BULK-85da6a04
17924 Bulk Product 4b6059f5 Home & Garden $302.18 205 2.6 50 BULK-f4586407
17925 Bulk Product a138d714 Home & Garden $321.38 207 0.8 40 BULK-8f8b2fa8
17926 Bulk Product 97757e79 Home & Garden $403.72 38 4.9 45 BULK-8ea69435
17927 Bulk Product 3e99c01c Clothing $233.65 463 3.5 3 BULK-ea4abada
17928 Bulk Product ce8a48dc Books $952.74 141 3.3 66 BULK-523ade89
17929 Bulk Product ba044b3d Home & Garden $210.96 195 1.6 49 BULK-360fc997
17930 Bulk Product 83700da7 Clothing $790.66 409 2.3 6 BULK-8756fbd3
17931 Bulk Product 396d4ca2 Home & Garden $654.29 452 1.9 19 BULK-73639da4
17932 Bulk Product a2d8b554 Sports & Outdoors $717.06 456 4.7 98 BULK-576606aa
17933 Bulk Product 51655364 Electronics $807.70 460 3.5 44 BULK-95c188f1
17934 Bulk Product fce03f00 Toys & Games $767.23 131 1.6 89 BULK-d2e97b47
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