Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

350 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 350 Results Showing 8726 - 8750 of 24441

ID Name Category Price Stock Rating Reviews SKU
9285 Bulk Product 8d02dec7 Toys & Games $906.24 347 3.6 53 BULK-09bd20d5
9286 Bulk Product 08d74691 Toys & Games $246.63 189 4.9 55 BULK-9a8b7624
9287 Bulk Product a64526f2 Home & Garden $354.77 8 1.1 99 BULK-8d799e43
9288 Bulk Product 35fedd06 Toys & Games $758.57 99 2.6 10 BULK-6fbbffdb
9289 Bulk Product 089455c9 Clothing $718.64 189 0.2 47 BULK-3d4a3b0c
9290 Bulk Product 55dbf95f Clothing $245.18 430 2.0 61 BULK-4c5369ef
9291 Bulk Product 7d66d337 Books $56.85 294 1.8 57 BULK-69c3256b
9292 Bulk Product d18d4afc Sports & Outdoors $69.55 422 3.4 3 BULK-f809d6a3
9293 Bulk Product b78c628f Electronics $689.84 351 2.8 97 BULK-29c97abd
9294 Bulk Product 4e2da4d2 Toys & Games $53.59 152 1.9 27 BULK-e4d5c08c
9295 Bulk Product db62bafe Electronics $762.05 352 0.3 47 BULK-80864895
9296 Bulk Product cebd480c Books $81.09 146 1.6 63 BULK-75808b0f
9297 Bulk Product 9e881dc2 Electronics $45.43 202 4.0 6 BULK-da467246
9298 Bulk Product ac5b41fd Home & Garden $288.40 312 1.1 24 BULK-c2aaf896
9299 Bulk Product 3115f024 Books $433.45 56 4.0 2 BULK-2c8171af
9300 Bulk Product 07409a11 Sports & Outdoors $487.46 229 3.4 51 BULK-a0a71325
9301 Bulk Product 11be98c8 Electronics $981.57 375 0.2 51 BULK-4f83eafb
9302 Bulk Product 3e96fe78 Sports & Outdoors $925.64 278 0.1 7 BULK-227796d8
9303 Bulk Product 1eee9590 Sports & Outdoors $820.53 194 4.1 63 BULK-91be0063
9304 Bulk Product 5e48c52d Home & Garden $882.70 169 3.1 94 BULK-ed560e71
9305 Bulk Product 5c246016 Home & Garden $173.17 315 0.8 50 BULK-a9fb9afb
9306 Bulk Product cb93004f Sports & Outdoors $33.16 307 1.4 13 BULK-4f0e9846
9307 Bulk Product e4637ede Electronics $173.35 72 1.2 95 BULK-9ce590c0
9308 Bulk Product 6323a0d7 Books $992.40 38 2.7 39 BULK-c8d12d0c
9309 Bulk Product 76d3f5db Electronics $488.90 434 0.8 22 BULK-f85a0f76
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