Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

10 ms

Page Size

25

Current Page

415 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 415 Results Showing 10351 - 10375 of 24441

ID Name Category Price Stock Rating Reviews SKU
10910 Bulk Product fee8e4ff Electronics $492.45 74 4.0 19 BULK-4c8df7c6
10911 Bulk Product 4eef1537 Home & Garden $359.32 265 3.0 0 BULK-abfb8102
10912 Bulk Product 5da5c27d Home & Garden $694.20 350 3.1 20 BULK-c7003cba
10913 Bulk Product 23aed50c Electronics $33.82 315 4.9 46 BULK-6b83edd2
10914 Bulk Product 978cfdef Toys & Games $659.59 50 4.3 50 BULK-3b369bf9
10915 Bulk Product 38ca3f4b Electronics $1,002.19 83 3.2 49 BULK-d4bea6c8
10916 Bulk Product 9aed1d0d Electronics $356.49 440 1.3 15 BULK-65978280
10917 Bulk Product c23e34bc Toys & Games $75.85 167 0.5 60 BULK-fab30c16
10918 Bulk Product 88452c59 Books $394.36 10 2.9 34 BULK-5b9bca1a
10919 Bulk Product 862c422e Toys & Games $236.53 80 4.4 89 BULK-1c9349d6
10920 Bulk Product 722e4877 Toys & Games $889.93 140 1.0 16 BULK-c56f937e
10921 Bulk Product 4372ebf4 Toys & Games $633.99 386 3.4 30 BULK-27c00995
10922 Bulk Product cdfb4f8a Books $932.93 451 0.7 81 BULK-7a764fc7
10923 Bulk Product 51ee7ede Sports & Outdoors $866.59 377 2.0 14 BULK-244d753c
10924 Bulk Product 2af12772 Books $507.97 18 4.4 89 BULK-0087bdc5
10925 Bulk Product 4c7fd038 Sports & Outdoors $75.25 42 2.3 97 BULK-5839c794
10926 Bulk Product 806255dd Sports & Outdoors $652.00 326 3.5 3 BULK-90e07efe
10927 Bulk Product bbfd8b47 Home & Garden $501.30 204 3.0 63 BULK-d19b63e3
10928 Bulk Product 8926910b Sports & Outdoors $331.82 301 0.6 9 BULK-73d67a99
10929 Bulk Product aee31c86 Toys & Games $178.57 449 2.8 31 BULK-64f6405d
10930 Bulk Product fadada1b Books $642.87 185 1.4 82 BULK-7425e4ec
10931 Bulk Product 5c1a7ed8 Clothing $524.89 362 3.1 6 BULK-981edbae
10932 Bulk Product b8ed421c Electronics $799.11 78 4.7 48 BULK-c4285a2e
10933 Bulk Product a1b43207 Home & Garden $604.42 38 4.1 64 BULK-1ce45a65
10934 Bulk Product b740f57a Toys & Games $967.29 294 4.1 47 BULK-8b80499a
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