Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

25

Current Page

656 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 656 Results Showing 16376 - 16400 of 24441

ID Name Category Price Stock Rating Reviews SKU
16935 Bulk Product 5424cd74 Toys & Games $123.29 477 2.7 0 BULK-a8df1ed2
16936 Bulk Product fb3e7150 Electronics $881.68 73 1.1 48 BULK-e75ab37d
16937 Bulk Product a30a7489 Clothing $135.47 185 3.0 51 BULK-53cfce90
16938 Bulk Product 45f0a89a Toys & Games $575.99 198 1.8 65 BULK-eab8adad
16939 Bulk Product 2fb1f3b0 Toys & Games $760.35 419 0.4 47 BULK-d1a1340e
16940 Bulk Product db833714 Electronics $251.58 383 3.3 31 BULK-aed28a86
16941 Bulk Product ee220180 Home & Garden $120.68 285 4.4 50 BULK-0b8c52c9
16942 Bulk Product 24400e41 Sports & Outdoors $116.18 149 1.8 49 BULK-b8b7fe47
16943 Bulk Product 854dea66 Electronics $878.04 187 2.4 17 BULK-3874a226
16944 Bulk Product cec63173 Books $563.45 227 1.0 29 BULK-50c0b4e7
16945 Bulk Product 0edcdac3 Electronics $396.76 405 4.1 0 BULK-8614ba12
16946 Bulk Product 082b1467 Sports & Outdoors $91.28 211 4.2 62 BULK-ffa84bcd
16947 Bulk Product 68ad4e98 Books $107.59 337 1.0 92 BULK-bf201162
16948 Bulk Product 944e5b07 Home & Garden $169.01 254 2.1 55 BULK-3cdb5aac
16949 Bulk Product e2cf148f Electronics $554.18 266 4.0 5 BULK-c8f4a381
16950 Bulk Product ebcb0705 Home & Garden $617.13 255 4.4 59 BULK-e2c623c7
16951 Bulk Product 256d1267 Clothing $722.76 420 0.7 85 BULK-50a51ef4
16952 Bulk Product 9dbb44b2 Home & Garden $745.97 337 4.4 7 BULK-44a0c1f6
16953 Bulk Product e1335e68 Home & Garden $672.50 19 3.7 5 BULK-fa4c47a7
16954 Bulk Product 2eb56b8f Toys & Games $920.19 152 2.3 61 BULK-236f2887
16955 Bulk Product 9d083c0e Home & Garden $614.50 197 1.2 26 BULK-b07105c2
16956 Bulk Product 5b041c5e Electronics $690.72 314 2.7 1 BULK-a3baba91
16957 Bulk Product f6bd2e32 Sports & Outdoors $77.73 217 3.1 79 BULK-c440583c
16958 Bulk Product 54541b24 Electronics $366.78 96 4.7 28 BULK-4c2767b2
16959 Bulk Product 137babe5 Sports & Outdoors $526.62 105 2.5 27 BULK-5941490e
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