Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

35 ms

Page Size

25

Current Page

254 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 254 Results Showing 6326 - 6350 of 24441

ID Name Category Price Stock Rating Reviews SKU
6885 Bulk Product 11278740 Home & Garden $987.56 239 0.2 2 BULK-836ce3bc
6886 Bulk Product d46afb72 Home & Garden $917.69 40 0.9 9 BULK-60060669
6887 Bulk Product 87dc2b9c Clothing $466.78 159 4.3 71 BULK-23adbdce
6888 Bulk Product b74994cc Clothing $47.09 325 1.9 37 BULK-4b75eadc
6889 Bulk Product 2e7f7279 Toys & Games $782.46 465 4.2 57 BULK-ea315867
6890 Bulk Product a1a56622 Clothing $164.57 402 4.7 2 BULK-51fc9ff3
6891 Bulk Product 108cbc65 Sports & Outdoors $393.26 218 0.2 77 BULK-3883a9cf
6892 Bulk Product 1d75d82b Books $190.42 349 3.1 17 BULK-04f4b91a
6893 Bulk Product f93a3062 Books $558.86 204 2.4 65 BULK-b1d38519
6894 Bulk Product c9ca6f05 Electronics $357.79 445 3.2 81 BULK-bd195b52
6895 Bulk Product 543dc86b Home & Garden $722.39 323 4.9 37 BULK-f90de1f6
6896 Bulk Product 367257c1 Home & Garden $962.82 186 3.9 31 BULK-f022f86d
6897 Bulk Product f197a3f6 Books $354.05 487 2.0 51 BULK-3c29dd86
6898 Bulk Product 05c349c9 Electronics $615.72 185 0.5 32 BULK-4d14df64
6899 Bulk Product 26fd22cd Electronics $570.21 167 2.7 40 BULK-a8c94572
6900 Bulk Product 23a9df2b Sports & Outdoors $999.61 220 1.4 9 BULK-87c9e48d
6901 Bulk Product 5ec92c35 Clothing $331.10 75 2.4 96 BULK-df438111
6902 Bulk Product f5992ba8 Books $480.26 203 4.2 29 BULK-c987070f
6903 Bulk Product eaa30a69 Home & Garden $988.06 142 2.5 26 BULK-11811dbc
6904 Bulk Product 80d3cd67 Toys & Games $877.56 100 1.4 41 BULK-8aa4068e
6905 Bulk Product 5ce77209 Toys & Games $978.26 257 1.6 51 BULK-d695181f
6906 Bulk Product 794d3b7d Electronics $808.28 136 3.7 38 BULK-45850f73
6907 Bulk Product ebd3c3cf Home & Garden $1,009.56 499 4.6 6 BULK-73f1ba45
6908 Bulk Product a873e3c6 Electronics $297.02 482 3.1 7 BULK-460e604a
6909 Bulk Product fdafc5f9 Toys & Games $127.43 490 2.3 86 BULK-146cdc38
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