Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

790 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 790 Results Showing 19726 - 19750 of 24441

ID Name Category Price Stock Rating Reviews SKU
20285 Bulk Product c48cc1cf Toys & Games $406.41 215 2.7 69 BULK-b9e488fa
20286 Bulk Product e08313ab Electronics $439.08 404 0.5 74 BULK-135bf68e
20287 Bulk Product b68071b4 Clothing $824.39 220 2.0 31 BULK-0cb32807
20288 Bulk Product 02a7196b Books $351.96 467 1.4 21 BULK-6835c86a
20289 Bulk Product becc6c7d Clothing $73.99 38 0.2 88 BULK-8eb325fc
20290 Bulk Product beb63966 Clothing $847.69 309 4.8 96 BULK-90ec1600
20291 Bulk Product 6899b681 Sports & Outdoors $704.49 326 1.5 73 BULK-23e2a501
20292 Bulk Product 2aee2a67 Electronics $658.53 296 0.4 24 BULK-69cdf382
20293 Bulk Product 421fbf69 Toys & Games $90.25 124 3.4 6 BULK-8606b138
20294 Bulk Product 2e9dbeee Electronics $590.02 86 1.5 75 BULK-310b2b70
20295 Bulk Product cbfd6a6f Home & Garden $923.40 489 4.4 18 BULK-ecf64a08
20296 Bulk Product a24ff7f7 Clothing $740.60 194 1.4 34 BULK-20cb853f
20297 Bulk Product be786d01 Sports & Outdoors $300.25 436 0.7 53 BULK-83629aae
20298 Bulk Product 98828080 Sports & Outdoors $39.69 136 2.7 21 BULK-a88826ca
20299 Bulk Product 6548883d Sports & Outdoors $413.66 316 3.4 32 BULK-3d56da98
20300 Bulk Product 3dd85102 Clothing $536.85 286 0.0 65 BULK-ecd0da15
20301 Bulk Product f32cd63f Electronics $116.62 35 1.2 95 BULK-9ed65df8
20302 Bulk Product 0b2b1453 Home & Garden $754.45 413 2.8 53 BULK-4064bbc3
20303 Bulk Product ca14715d Home & Garden $269.40 181 0.9 34 BULK-7a89c822
20304 Bulk Product 3aa33f32 Electronics $758.90 251 1.6 58 BULK-d2db0f69
20305 Bulk Product 6d0514b0 Electronics $84.65 239 3.9 44 BULK-c8179dd9
20306 Bulk Product 80f4d880 Clothing $804.40 213 1.9 37 BULK-09f14f97
20307 Bulk Product ffadc538 Books $704.70 308 1.2 84 BULK-a8183bdc
20308 Bulk Product 7464d9cc Sports & Outdoors $880.51 445 0.3 68 BULK-94717c2f
20309 Bulk Product 3842faf3 Toys & Games $707.57 165 0.3 23 BULK-3efc37e4
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