Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

933 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 933 Results Showing 23301 - 23325 of 24441

ID Name Category Price Stock Rating Reviews SKU
23860 Bulk Product 380b80d7 Toys & Games $93.77 242 3.9 92 BULK-587eb43e
23861 Bulk Product fc086eb5 Home & Garden $765.57 282 3.5 91 BULK-8f0c6143
23862 Bulk Product 827eb389 Home & Garden $185.34 400 1.8 7 BULK-4afbef4d
23863 Bulk Product c99c9c19 Clothing $511.29 19 1.0 89 BULK-f82ef05d
23864 Bulk Product cd35eccc Toys & Games $382.66 359 3.5 90 BULK-bb955007
23865 Bulk Product 2e4e4f35 Sports & Outdoors $806.85 156 0.8 40 BULK-12f2a7aa
23866 Bulk Product 61ed0ab9 Electronics $24.81 487 1.0 88 BULK-3e59e520
23867 Bulk Product 5b59fbc3 Sports & Outdoors $79.75 395 2.1 93 BULK-d1252600
23868 Bulk Product cdb95fe3 Electronics $942.84 269 0.9 57 BULK-1334fe32
23869 Bulk Product 0e6ebb30 Books $120.85 403 4.0 29 BULK-3b345a46
23870 Bulk Product 24e3d2cb Sports & Outdoors $991.04 432 0.4 95 BULK-83bf1221
23871 Bulk Product 27e1737e Clothing $858.69 414 0.5 54 BULK-57514992
23872 Bulk Product 58c68fca Sports & Outdoors $422.04 152 4.2 86 BULK-7c747612
23873 Bulk Product 3d87c35b Toys & Games $207.00 44 3.0 10 BULK-d935f656
23874 Bulk Product e5a495e1 Sports & Outdoors $474.27 414 3.5 45 BULK-96d7c809
23875 Bulk Product 1adff345 Books $347.26 165 3.1 60 BULK-09e35850
23876 Bulk Product cf2bc1f8 Toys & Games $925.78 149 2.5 84 BULK-48cb78af
23877 Bulk Product fd588fa5 Toys & Games $573.35 302 3.5 78 BULK-5b601bc8
23878 Bulk Product 57bf5c60 Books $120.79 171 3.0 44 BULK-9771bcc1
23879 Bulk Product e50766ef Clothing $539.55 54 3.8 28 BULK-c73b30b1
23880 Bulk Product 643a33c4 Books $613.06 359 0.5 89 BULK-27aef50d
23881 Bulk Product 49d2a289 Sports & Outdoors $30.95 354 3.5 2 BULK-eb095ae6
23882 Bulk Product e22348d4 Clothing $663.64 477 2.1 91 BULK-7709bf02
23883 Bulk Product 2b452ca1 Electronics $832.06 235 0.9 63 BULK-c0646a8f
23884 Bulk Product 02fc7ac8 Electronics $788.06 172 1.9 84 BULK-5ae051f9
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