Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

250 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 250 Results Showing 6226 - 6250 of 24441

ID Name Category Price Stock Rating Reviews SKU
6785 Bulk Product 89ab7b08 Toys & Games $157.69 358 3.6 67 BULK-89c10581
6786 Bulk Product 95623d90 Electronics $615.40 117 4.7 80 BULK-498d1fb3
6787 Bulk Product f15b9864 Toys & Games $98.30 116 5.0 23 BULK-d0109fb0
6788 Bulk Product 9e93bbe2 Toys & Games $190.09 94 3.6 68 BULK-ab85f6ae
6789 Bulk Product 54b9d16b Books $833.00 232 2.7 67 BULK-971fd8f7
6790 Bulk Product 709a65b7 Books $433.26 449 3.1 56 BULK-88b3ae58
6791 Bulk Product 19d48a8b Books $501.56 208 2.9 57 BULK-d0ed5264
6792 Bulk Product 71588d65 Books $785.25 257 4.7 32 BULK-9d8aa214
6793 Bulk Product d558d982 Electronics $295.35 181 0.6 43 BULK-81529c4f
6794 Bulk Product 3982a8b5 Books $991.69 101 0.4 77 BULK-ef5cd56e
6795 Bulk Product 5c076025 Books $966.31 341 3.1 3 BULK-bcdbc5f9
6796 Bulk Product 32705e0e Sports & Outdoors $371.92 264 3.2 11 BULK-0bbf8611
6797 Bulk Product 847157ec Home & Garden $343.96 184 0.9 64 BULK-ec5a37c1
6798 Bulk Product 7a5d9439 Books $351.91 161 2.2 55 BULK-50a6ade8
6799 Bulk Product a15a8824 Toys & Games $369.12 228 0.4 29 BULK-a966e818
6800 Bulk Product 8a915da7 Books $619.75 297 2.9 84 BULK-e43e1057
6801 Bulk Product cccea2c5 Sports & Outdoors $49.63 271 2.1 16 BULK-a8f89f49
6802 Bulk Product 02faec33 Toys & Games $533.53 174 3.2 24 BULK-795ab879
6803 Bulk Product db1e2814 Sports & Outdoors $759.26 137 0.5 44 BULK-137ee27f
6804 Bulk Product 55f53c56 Toys & Games $227.44 369 0.5 23 BULK-a18e92f0
6805 Bulk Product a9529e5d Home & Garden $599.36 347 3.6 5 BULK-af121a27
6806 Bulk Product ff95f873 Books $152.62 365 1.0 8 BULK-75b096e4
6807 Bulk Product e866ee39 Books $627.01 389 3.7 65 BULK-e1bba7d7
6808 Bulk Product 7f85b97f Electronics $261.60 375 4.6 3 BULK-7610578d
6809 Bulk Product af2d2f5e Sports & Outdoors $300.27 463 3.5 74 BULK-382fbd73
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