Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

52 ms

Page Size

25

Current Page

773 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 773 Results Showing 19301 - 19325 of 24441

ID Name Category Price Stock Rating Reviews SKU
19860 Bulk Product 555dde41 Home & Garden $250.23 72 1.1 97 BULK-f6f7a755
19861 Bulk Product 97ed1e3a Sports & Outdoors $766.81 437 1.0 44 BULK-6f66deca
19862 Bulk Product 839466af Books $272.09 294 2.2 57 BULK-980ec95f
19863 Bulk Product 08d2976c Electronics $137.79 143 0.8 2 BULK-378c46d4
19864 Bulk Product affbd540 Home & Garden $281.95 216 3.8 47 BULK-6b6ecaa5
19865 Bulk Product 32bdc2b3 Home & Garden $449.11 465 1.3 95 BULK-fdee6d7c
19866 Bulk Product ae3733a2 Toys & Games $572.25 383 0.3 78 BULK-badf3cf4
19867 Bulk Product b6422d53 Clothing $290.14 75 4.4 55 BULK-e5796cc1
19868 Bulk Product 810df8c7 Books $279.32 316 1.2 43 BULK-4e91177d
19869 Bulk Product 4b5fe02e Home & Garden $594.92 298 0.5 19 BULK-b6670bf4
19870 Bulk Product b5da8d89 Home & Garden $453.27 122 1.5 94 BULK-1e614e19
19871 Bulk Product 30a4eb03 Sports & Outdoors $866.02 252 1.2 59 BULK-a191084d
19872 Bulk Product 28763b49 Home & Garden $659.22 403 2.9 59 BULK-502c2420
19873 Bulk Product 671b285e Clothing $935.12 460 4.2 31 BULK-cd7a109e
19874 Bulk Product 5e91a10d Books $492.51 493 4.7 48 BULK-4ee3bf0a
19875 Bulk Product 53c8e014 Electronics $189.45 11 1.4 94 BULK-5ed18321
19876 Bulk Product eb5dd840 Electronics $279.19 490 3.3 35 BULK-d853fe08
19877 Bulk Product a8e4c1e1 Home & Garden $995.98 203 1.8 99 BULK-d013af19
19878 Bulk Product acf3fe29 Sports & Outdoors $65.19 231 1.0 15 BULK-99eaa2ee
19879 Bulk Product 87352fe0 Home & Garden $500.50 291 0.9 26 BULK-4fa690b0
19880 Bulk Product 2adac319 Clothing $598.11 292 4.0 38 BULK-cd55f484
19881 Bulk Product d1f28d91 Toys & Games $617.38 415 4.6 81 BULK-6f799c06
19882 Bulk Product 5c1885e4 Toys & Games $35.43 219 0.6 13 BULK-a6d28806
19883 Bulk Product ce2633bc Electronics $222.55 270 4.0 21 BULK-a96ed0a4
19884 Bulk Product d28d2561 Books $296.33 412 2.8 32 BULK-a176f138
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