Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

754 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 754 Results Showing 18826 - 18850 of 24441

ID Name Category Price Stock Rating Reviews SKU
19385 Bulk Product 03469fc0 Books $634.20 348 2.3 7 BULK-5698c7e5
19386 Bulk Product 2704b30f Toys & Games $921.01 194 0.8 90 BULK-9012c79c
19387 Bulk Product e32c64f7 Home & Garden $438.09 222 3.3 92 BULK-07533b95
19388 Bulk Product a6a2710e Home & Garden $92.84 471 5.0 55 BULK-8d768181
19389 Bulk Product 2c483bb8 Clothing $129.92 71 4.0 46 BULK-dfb62ff7
19390 Bulk Product 50eb1089 Sports & Outdoors $384.98 264 0.6 24 BULK-9dbf02b5
19391 Bulk Product 3c2122cc Toys & Games $734.10 175 2.2 24 BULK-358ce26c
19392 Bulk Product 0257513c Toys & Games $727.07 416 1.7 58 BULK-bd049664
19393 Bulk Product 8be4efdf Toys & Games $541.92 412 1.0 77 BULK-5ee6f858
19394 Bulk Product af375677 Sports & Outdoors $979.17 177 3.3 14 BULK-680a8d69
19395 Bulk Product 6abb5d80 Clothing $493.01 226 3.3 12 BULK-538a62f7
19396 Bulk Product c93adf0a Home & Garden $884.37 408 0.6 65 BULK-b03b1cc2
19397 Bulk Product ae49f9db Clothing $223.96 457 2.5 14 BULK-c969c3cb
19398 Bulk Product fb087cb3 Home & Garden $43.10 168 3.0 6 BULK-3e5e229d
19399 Bulk Product 09d37240 Home & Garden $87.61 141 1.3 35 BULK-f0904100
19400 Bulk Product 1cb57427 Electronics $709.82 257 2.0 16 BULK-d746799e
19401 Bulk Product e492b21b Books $962.29 435 2.9 67 BULK-a6bdfba9
19402 Bulk Product c9a7d8ff Electronics $660.52 94 3.8 51 BULK-bd4b7571
19403 Bulk Product d318e11c Clothing $113.51 496 0.0 49 BULK-794fd3ee
19404 Bulk Product 82523fb7 Home & Garden $342.73 152 3.3 40 BULK-ad0cfef1
19405 Bulk Product 587c5d17 Clothing $977.69 341 3.2 96 BULK-26dadc0c
19406 Bulk Product 442202bc Home & Garden $565.61 243 4.4 97 BULK-221e8c7d
19407 Bulk Product 4b3020aa Electronics $465.54 410 3.1 20 BULK-1d0b8516
19408 Bulk Product 093c810c Clothing $207.06 409 4.1 6 BULK-cf5176f5
19409 Bulk Product 2ad380ec Books $820.52 252 3.1 81 BULK-3af4d980
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