Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

54 ms

Page Size

50

Current Page

114 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 114 Results Showing 5651 - 5700 of 24441

ID Name Category Price Stock Rating Reviews SKU
6210 Bulk Product 6c2e9fec Electronics $366.25 314 2.0 59 BULK-002bf24f
6211 Bulk Product 3b9a59bc Electronics $542.02 111 2.2 86 BULK-e59aaf73
6212 Bulk Product 4878eaa6 Toys & Games $366.13 180 3.0 73 BULK-b351f67a
6213 Bulk Product c09e8eb4 Toys & Games $652.01 374 2.3 44 BULK-21e155d0
6214 Bulk Product 149b39b7 Sports & Outdoors $184.87 414 2.9 14 BULK-d6e9f4cb
6215 Bulk Product 2d2bf5ee Electronics $931.68 196 4.0 10 BULK-82054587
6216 Bulk Product fb38597b Home & Garden $24.32 411 4.2 12 BULK-90ceddd6
6217 Bulk Product d780c12a Toys & Games $402.42 146 5.0 89 BULK-751592e6
6218 Bulk Product 24343d22 Sports & Outdoors $735.98 447 2.3 55 BULK-cda26e2d
6219 Bulk Product e1733599 Toys & Games $965.01 98 3.3 79 BULK-7d510947
6220 Bulk Product 833f19a0 Toys & Games $400.40 317 4.2 84 BULK-bc93e931
6221 Bulk Product 8e21f360 Clothing $22.22 138 1.6 84 BULK-bcc53668
6222 Bulk Product 596e10c6 Books $261.67 237 0.3 39 BULK-b2ee5144
6223 Bulk Product 9042f5f9 Home & Garden $742.45 137 3.3 3 BULK-95f987b9
6224 Bulk Product d6fff785 Toys & Games $955.61 315 4.6 41 BULK-6fb1f3b6
6225 Bulk Product 746b7e25 Toys & Games $293.97 129 3.9 62 BULK-366a06ef
6226 Bulk Product 10c1b5a1 Sports & Outdoors $318.11 21 3.6 89 BULK-ccdc49fe
6227 Bulk Product e24c7a4d Clothing $438.64 405 4.8 3 BULK-99171622
6228 Bulk Product a09f6850 Sports & Outdoors $858.92 487 2.6 1 BULK-9f24d71d
6229 Bulk Product 0be6232d Toys & Games $56.12 221 2.4 13 BULK-1fa3fa67
6230 Bulk Product d0606ce4 Sports & Outdoors $947.41 463 3.2 76 BULK-c52d468c
6231 Bulk Product 4cd04f0f Books $765.02 114 4.7 77 BULK-477b2d08
6232 Bulk Product d0ef2041 Clothing $291.17 101 0.7 46 BULK-bb45de33
6233 Bulk Product b5cda77c Home & Garden $392.10 80 4.3 40 BULK-fd7b59d6
6234 Bulk Product a3548101 Home & Garden $260.14 234 1.9 9 BULK-9e00fb8d
6235 Bulk Product 57ec0f50 Books $32.44 137 2.1 35 BULK-2c79b6ee
6236 Bulk Product 4b281b6a Toys & Games $523.77 105 3.2 78 BULK-a4897f4b
6237 Bulk Product 49729384 Home & Garden $277.28 215 0.6 56 BULK-5a69479d
6238 Bulk Product 07f0bc72 Toys & Games $421.13 251 3.4 68 BULK-e1a23d43
6239 Bulk Product e194b6ac Clothing $654.22 332 1.9 56 BULK-3780ea2d
6240 Bulk Product b33fa9e3 Electronics $649.27 373 0.6 70 BULK-1247650f
6241 Bulk Product cbf37716 Books $704.55 172 0.6 18 BULK-d9f6e48d
6242 Bulk Product 732bf799 Electronics $738.36 331 3.7 6 BULK-94eb6dbe
6243 Bulk Product 99f5aa37 Books $929.27 99 3.6 82 BULK-e16f1330
6244 Bulk Product c2a072a9 Toys & Games $445.49 299 4.3 7 BULK-bcbac899
6245 Bulk Product 0ad69024 Electronics $212.76 393 0.9 37 BULK-492737e0
6246 Bulk Product fb95ab53 Clothing $383.55 65 3.0 67 BULK-1e64aa86
6247 Bulk Product 296cce9a Toys & Games $890.17 391 0.7 94 BULK-3fe8ae64
6248 Bulk Product 253f0b46 Electronics $703.47 220 1.9 73 BULK-e5cf0f89
6249 Bulk Product 6948f81b Toys & Games $429.37 13 1.5 15 BULK-bd2c279c
6250 Bulk Product 2fd016f0 Home & Garden $341.97 320 4.2 75 BULK-22506ab5
6251 Bulk Product 9e516a5e Home & Garden $720.37 130 4.5 27 BULK-c83834b7
6252 Bulk Product 25b90ac5 Toys & Games $480.47 268 0.6 70 BULK-2d63fd09
6253 Bulk Product 9fd4db9e Books $796.88 467 4.6 55 BULK-cc0e7976
6254 Bulk Product f79f058b Home & Garden $692.69 89 2.4 46 BULK-cc024b3d
6255 Bulk Product b48b0487 Toys & Games $351.27 316 4.8 33 BULK-efc723f1
6256 Bulk Product bac31c88 Sports & Outdoors $213.45 491 2.8 74 BULK-5a8a77a7
6257 Bulk Product 6de7ca38 Home & Garden $985.39 152 3.1 94 BULK-e55aa057
6258 Bulk Product 8ff2bcb8 Sports & Outdoors $571.29 246 1.2 24 BULK-d0bb12c0
6259 Bulk Product 8972cdf8 Home & Garden $58.32 121 1.7 28 BULK-1bd64392
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