Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

25

Current Page

847 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 847 Results Showing 21151 - 21175 of 24441

ID Name Category Price Stock Rating Reviews SKU
21710 Bulk Product b46ca3e1 Books $580.18 123 4.6 17 BULK-580dcce3
21711 Bulk Product 1bfbb7c8 Sports & Outdoors $351.44 228 2.7 53 BULK-06d35484
21712 Bulk Product aebda95d Home & Garden $507.20 115 0.3 26 BULK-4512d426
21713 Bulk Product 73695f39 Electronics $922.74 129 0.3 10 BULK-6445c09d
21714 Bulk Product 6e3292a9 Toys & Games $804.20 307 3.8 79 BULK-4422c5bb
21715 Bulk Product 39d4952a Home & Garden $524.66 253 4.9 41 BULK-03d081fa
21716 Bulk Product c7cae469 Clothing $766.00 379 4.2 19 BULK-c2ce29bc
21717 Bulk Product 9c50f795 Toys & Games $566.39 83 3.3 9 BULK-ece6232f
21718 Bulk Product 3d4184c4 Toys & Games $985.72 114 3.8 82 BULK-dba8700b
21719 Bulk Product 2efde35e Clothing $601.18 293 1.4 45 BULK-f8ca0b2a
21720 Bulk Product c417492f Sports & Outdoors $896.07 59 0.9 31 BULK-eed9721d
21721 Bulk Product 4a907087 Clothing $747.83 393 4.3 11 BULK-0a6b741b
21722 Bulk Product c743f4b3 Home & Garden $640.02 242 3.4 80 BULK-4bf750dd
21723 Bulk Product 8c155ab0 Home & Garden $620.90 145 3.1 70 BULK-d291d83c
21724 Bulk Product bb64f9a3 Books $767.41 374 1.7 25 BULK-3370602c
21725 Bulk Product 0be04b0c Sports & Outdoors $47.57 401 3.4 78 BULK-c6a67d8f
21726 Bulk Product 882c6a51 Sports & Outdoors $990.90 126 4.9 93 BULK-f05e05d3
21727 Bulk Product 776237d9 Clothing $826.67 175 0.0 33 BULK-194adba5
21728 Bulk Product c3f1f6b2 Toys & Games $633.51 214 2.5 97 BULK-15b42257
21729 Bulk Product d5f41d0c Sports & Outdoors $757.57 360 1.1 72 BULK-dd93a982
21730 Bulk Product 03c221e8 Home & Garden $168.78 183 4.2 11 BULK-2c2c6d2a
21731 Bulk Product 177b7d81 Books $55.47 347 2.0 25 BULK-9836b1e5
21732 Bulk Product 8de07a0c Toys & Games $81.78 478 2.3 64 BULK-38cc7293
21733 Bulk Product 522a32de Home & Garden $355.44 3 1.9 6 BULK-bd7d0ed6
21734 Bulk Product e06a6d56 Toys & Games $331.54 75 1.2 90 BULK-95de1d4e
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