Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

620 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 620 Results Showing 15476 - 15500 of 24441

ID Name Category Price Stock Rating Reviews SKU
16035 Bulk Product e8d67ee7 Home & Garden $303.92 493 4.8 44 BULK-b4dacfda
16036 Bulk Product 352e3c38 Sports & Outdoors $500.43 453 3.8 45 BULK-40ab399a
16037 Bulk Product cdc25627 Sports & Outdoors $285.08 227 0.9 94 BULK-08d25385
16038 Bulk Product 9cfc2675 Home & Garden $143.31 32 4.0 74 BULK-90f16936
16039 Bulk Product 64f33110 Toys & Games $333.00 183 2.9 52 BULK-a4fd4acb
16040 Bulk Product 5ef29d69 Toys & Games $99.47 223 1.3 47 BULK-8e45daeb
16041 Bulk Product 05f585e1 Books $66.29 188 1.4 21 BULK-d1c05b4d
16042 Bulk Product bc197673 Sports & Outdoors $56.71 7 0.6 81 BULK-6ac403f5
16043 Bulk Product 3f995883 Toys & Games $295.79 273 3.1 62 BULK-ac0ee8e4
16044 Bulk Product da68a099 Clothing $923.92 197 1.5 41 BULK-7ead32c3
16045 Bulk Product 00163515 Toys & Games $771.22 221 0.0 60 BULK-21c25746
16046 Bulk Product d57c7b76 Clothing $55.04 433 2.0 58 BULK-ed6fa05f
16047 Bulk Product ffcb093a Electronics $535.01 400 0.6 62 BULK-d5ca0803
16048 Bulk Product 0d24d6dc Home & Garden $975.98 361 4.6 4 BULK-5f6593bc
16049 Bulk Product 2dd21011 Electronics $901.28 434 2.1 2 BULK-86a0d71b
16050 Bulk Product e74add35 Books $55.83 27 2.1 90 BULK-6d53473f
16051 Bulk Product 95438ddc Home & Garden $12.36 357 2.7 25 BULK-338fa9ad
16052 Bulk Product 9d9dd3a7 Clothing $404.75 293 3.2 1 BULK-b1c400d7
16053 Bulk Product a95a4e71 Clothing $37.12 325 4.0 69 BULK-be8b3c7e
16054 Bulk Product c173f02f Sports & Outdoors $720.64 308 3.7 1 BULK-eec2f218
16055 Bulk Product f4c1fea8 Electronics $782.43 334 4.9 65 BULK-82a89174
16056 Bulk Product 844617c6 Sports & Outdoors $767.98 34 4.1 63 BULK-4a277bca
16057 Bulk Product 2feaf087 Sports & Outdoors $629.32 162 4.4 31 BULK-cc3afd64
16058 Bulk Product 1eddbbf3 Books $224.85 472 3.3 53 BULK-284f87f8
16059 Bulk Product ed26945c Toys & Games $1,004.69 16 0.5 94 BULK-8a397350
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