Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

573 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 573 Results Showing 14301 - 14325 of 24441

ID Name Category Price Stock Rating Reviews SKU
14860 Bulk Product a7171e3b Electronics $751.66 171 2.1 28 BULK-b35eafac
14861 Bulk Product 0c5c29bb Clothing $340.66 141 0.2 0 BULK-18a45928
14862 Bulk Product a78bd521 Electronics $306.91 405 3.7 56 BULK-d0d1c26f
14863 Bulk Product 012e6cbe Sports & Outdoors $485.51 182 2.4 87 BULK-fc90bc26
14864 Bulk Product 768c8a75 Toys & Games $126.32 469 1.1 9 BULK-b7faa08c
14865 Bulk Product bc2ebedd Sports & Outdoors $531.81 147 3.9 64 BULK-1407bbfc
14866 Bulk Product f52057e8 Books $472.52 361 2.8 24 BULK-a11973ca
14867 Bulk Product 4b845992 Clothing $292.52 108 0.2 10 BULK-0fd609d6
14868 Bulk Product 15b7419c Sports & Outdoors $65.77 418 1.9 78 BULK-57a00ef6
14869 Bulk Product 941a9cc0 Sports & Outdoors $249.27 250 3.4 30 BULK-dddb0fed
14870 Bulk Product 726d08ed Home & Garden $797.33 96 0.8 24 BULK-826c43ea
14871 Bulk Product 53e8d218 Electronics $914.37 286 4.7 95 BULK-0a52126b
14872 Bulk Product 4fc37f51 Toys & Games $154.88 235 1.8 83 BULK-00b505c2
14873 Bulk Product 7833e97d Electronics $771.35 99 1.2 29 BULK-2e29b2a7
14874 Bulk Product da9eab32 Electronics $121.88 498 2.9 86 BULK-aa9fafaf
14875 Bulk Product 6ceed537 Sports & Outdoors $119.03 460 4.0 86 BULK-ebd9423a
14876 Bulk Product 0d8e4d1a Electronics $488.65 472 1.5 1 BULK-ac0b66c8
14877 Bulk Product df572c8f Sports & Outdoors $493.13 72 4.9 53 BULK-57701633
14878 Bulk Product af428279 Toys & Games $550.74 377 2.1 47 BULK-400661f3
14879 Bulk Product 8427719f Books $78.92 419 4.5 8 BULK-511b585a
14880 Bulk Product ab6e8df9 Books $981.91 187 0.2 65 BULK-37e74afc
14881 Bulk Product c58f883e Toys & Games $184.38 143 0.5 34 BULK-ed979bbe
14882 Bulk Product 27fd6a2a Toys & Games $25.54 485 4.4 58 BULK-bf404223
14883 Bulk Product 0abddb91 Home & Garden $688.23 223 3.4 30 BULK-fb20d1e0
14884 Bulk Product 88bfe23c Clothing $761.86 410 3.6 51 BULK-2ae7f158
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