Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

8 ms

Page Size

25

Current Page

219 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 219 Results Showing 5451 - 5475 of 24441

ID Name Category Price Stock Rating Reviews SKU
6010 Bulk Product 1d6ecec8 Electronics $460.33 283 0.5 25 BULK-e0e521e9
6011 Bulk Product b6824bd9 Toys & Games $16.97 286 2.6 36 BULK-14f3c5ac
6012 Bulk Product 7db6c786 Home & Garden $386.49 300 4.3 76 BULK-87b03ffc
6013 Bulk Product 7897f54b Toys & Games $25.40 142 3.1 80 BULK-544512f8
6014 Bulk Product ab0c29cd Toys & Games $441.07 234 1.2 30 BULK-1fea10e6
6015 Bulk Product f054ce6a Clothing $630.13 422 5.0 27 BULK-030bd37d
6016 Bulk Product d3d45943 Toys & Games $208.70 74 2.2 60 BULK-52e2f0c1
6017 Bulk Product 03f212ca Clothing $923.10 231 4.2 95 BULK-5443186d
6018 Bulk Product 78b7cc04 Sports & Outdoors $482.15 146 3.7 91 BULK-a0776085
6019 Bulk Product b61c5389 Toys & Games $192.17 293 1.9 78 BULK-a51877c1
6020 Bulk Product 6ccbb864 Electronics $861.57 44 4.8 36 BULK-84272007
6021 Bulk Product f1e0a637 Home & Garden $158.94 283 2.4 74 BULK-fec7ac3e
6022 Bulk Product 9e083632 Home & Garden $942.74 286 4.8 82 BULK-a7ae2ef1
6023 Bulk Product 9063fa6c Sports & Outdoors $821.70 448 0.9 19 BULK-a01c1dca
6024 Bulk Product 15407627 Electronics $688.10 138 3.9 24 BULK-7465f31e
6025 Bulk Product 2807ba3e Toys & Games $779.85 35 1.9 11 BULK-b3c55802
6026 Bulk Product 2f7cfb2e Sports & Outdoors $1,006.31 410 4.5 32 BULK-b8653906
6027 Bulk Product e272bbaa Sports & Outdoors $693.25 157 2.4 81 BULK-15c1bfd1
6028 Bulk Product 276f1c87 Books $823.06 324 3.6 36 BULK-10ca75a1
6029 Bulk Product 95b90677 Home & Garden $14.10 13 4.7 87 BULK-81cbfba7
6030 Bulk Product e40e4eea Books $541.33 366 4.1 81 BULK-d2d1ac23
6031 Bulk Product e0eeea34 Electronics $50.44 174 3.3 98 BULK-7d7b80f6
6032 Bulk Product 33e171ef Electronics $538.05 231 1.7 16 BULK-4ca69615
6033 Bulk Product 36a242e1 Clothing $713.68 212 0.5 50 BULK-17b0bf1d
6034 Bulk Product 9aef5e42 Books $925.98 229 2.2 94 BULK-7673f844
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