Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

50

Current Page

274 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 274 Results Showing 13651 - 13700 of 24441

ID Name Category Price Stock Rating Reviews SKU
14210 Bulk Product e979eec9 Electronics $950.02 328 1.6 15 BULK-edcfa7ca
14211 Bulk Product 68ca7c34 Sports & Outdoors $257.90 165 2.4 29 BULK-4616072d
14212 Bulk Product d6a16143 Books $109.10 489 0.8 45 BULK-d45ad925
14213 Bulk Product 2af96c74 Toys & Games $277.62 464 3.3 93 BULK-f4aeb64f
14214 Bulk Product 5affb1e5 Sports & Outdoors $172.40 177 3.9 1 BULK-15b53a6d
14215 Bulk Product 802bd257 Sports & Outdoors $580.06 390 4.8 88 BULK-ea2b6ae7
14216 Bulk Product 771bbd00 Sports & Outdoors $64.12 390 1.2 45 BULK-8601dbd0
14217 Bulk Product d7de4b31 Books $296.15 3 1.0 0 BULK-365bf5aa
14218 Bulk Product 26e915c5 Sports & Outdoors $979.83 220 1.9 37 BULK-cb7bec29
14219 Bulk Product 99a30912 Home & Garden $476.75 132 3.3 46 BULK-3496db06
14220 Bulk Product 01797e64 Electronics $870.06 486 1.3 73 BULK-d17fa504
14221 Bulk Product 44d57b67 Electronics $569.12 33 3.1 40 BULK-d365cc6a
14222 Bulk Product 2837c2a2 Sports & Outdoors $852.59 64 2.8 54 BULK-cb9070ef
14223 Bulk Product 630ffef7 Home & Garden $700.22 363 0.6 14 BULK-c395def3
14224 Bulk Product 182c1bf7 Books $387.03 120 4.0 49 BULK-80014cf7
14225 Bulk Product 6c9de133 Home & Garden $280.94 70 4.1 26 BULK-58887c71
14226 Bulk Product b51016fe Electronics $858.03 258 2.0 91 BULK-22f103d7
14227 Bulk Product 966e956d Electronics $346.91 171 2.5 28 BULK-6a3bdf2c
14228 Bulk Product 3bdf4b34 Sports & Outdoors $449.90 429 3.7 87 BULK-8f6bb2cc
14229 Bulk Product 039066af Toys & Games $135.99 240 0.0 0 BULK-fc3fe298
14230 Bulk Product be4b1e63 Clothing $732.58 161 3.9 48 BULK-0439d532
14231 Bulk Product 3c050d06 Sports & Outdoors $871.11 260 1.5 12 BULK-148fdd01
14232 Bulk Product 53834e84 Sports & Outdoors $844.82 237 3.9 34 BULK-2336a3b1
14233 Bulk Product c37af381 Electronics $706.47 150 0.9 87 BULK-e6c7ffed
14234 Bulk Product 8d017d27 Clothing $23.49 457 4.8 76 BULK-3445a2a8
14235 Bulk Product ff69ec79 Sports & Outdoors $1,004.25 192 2.3 39 BULK-c6354484
14236 Bulk Product 4f978dc1 Electronics $413.53 73 1.1 47 BULK-2786d6ad
14237 Bulk Product a3d0fab2 Toys & Games $998.50 17 1.2 44 BULK-121abe5c
14238 Bulk Product 85e20efd Toys & Games $196.46 146 4.4 14 BULK-fd444a08
14239 Bulk Product fa6e8c62 Electronics $112.35 79 2.9 92 BULK-2b2d70ae
14240 Bulk Product 4073b5c8 Toys & Games $934.81 242 2.4 93 BULK-8d346dd3
14241 Bulk Product 783b1830 Toys & Games $839.94 181 0.4 82 BULK-8841ecbc
14242 Bulk Product 25c9f2fc Clothing $686.34 109 4.8 73 BULK-d3f6f6ff
14243 Bulk Product 0e926406 Books $591.89 449 3.2 17 BULK-9c13a3c7
14244 Bulk Product 1845f40e Home & Garden $328.57 246 0.5 67 BULK-e169d4d3
14245 Bulk Product fa134795 Electronics $845.51 411 4.4 20 BULK-0f279a44
14246 Bulk Product cacc3eed Books $285.00 296 0.2 39 BULK-fb18e2ab
14247 Bulk Product b7128e17 Clothing $330.71 337 1.5 96 BULK-1b92a1bf
14248 Bulk Product 53a3e88c Electronics $178.06 138 3.2 94 BULK-9efa926a
14249 Bulk Product fabbd170 Home & Garden $871.54 379 2.4 7 BULK-1f7d89fc
14250 Bulk Product a30ae9dd Toys & Games $470.52 8 2.9 54 BULK-c20b806d
14251 Bulk Product 6bcc95f3 Clothing $60.09 37 4.6 22 BULK-893620ae
14252 Bulk Product d97987ea Toys & Games $753.00 475 1.6 52 BULK-48ff3f54
14253 Bulk Product 6205c0da Sports & Outdoors $253.76 341 2.6 66 BULK-6a09e22a
14254 Bulk Product 1741a4fd Electronics $408.86 464 2.7 63 BULK-85104e49
14255 Bulk Product 37941382 Home & Garden $283.30 21 0.4 79 BULK-c99f10dd
14256 Bulk Product de943bbd Clothing $384.57 339 4.7 49 BULK-1e17177e
14257 Bulk Product 9bb8f3f1 Books $847.42 204 1.9 93 BULK-013ce714
14258 Bulk Product d10eaaca Clothing $891.42 186 1.2 75 BULK-e5bd4f25
14259 Bulk Product 0ea00f5a Clothing $596.14 260 2.4 25 BULK-ca56efac
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