Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

11 ms

Page Size

25

Current Page

422 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 422 Results Showing 10526 - 10550 of 24441

ID Name Category Price Stock Rating Reviews SKU
11085 Bulk Product 4269bc54 Home & Garden $972.42 18 4.8 68 BULK-63a4cb3d
11086 Bulk Product d21407af Clothing $765.47 496 4.0 35 BULK-6a6daa01
11087 Bulk Product 2ccfefdd Toys & Games $785.06 365 4.1 23 BULK-95fe74d7
11088 Bulk Product 407773c3 Home & Garden $363.57 214 2.8 63 BULK-333e4868
11089 Bulk Product 214c0223 Sports & Outdoors $42.17 17 4.0 42 BULK-e3e572c8
11090 Bulk Product 8c102806 Electronics $817.24 495 0.6 41 BULK-abcfbc02
11091 Bulk Product d7f5e215 Sports & Outdoors $619.18 236 3.8 88 BULK-de67e84b
11092 Bulk Product f83b1179 Clothing $539.28 405 1.9 93 BULK-1f1bae22
11093 Bulk Product 2e9f2941 Sports & Outdoors $766.75 83 1.5 50 BULK-afa70fd2
11094 Bulk Product cea05317 Electronics $713.44 229 0.8 75 BULK-9ae84912
11095 Bulk Product 2d3d913f Clothing $589.54 363 2.8 97 BULK-ed5aab51
11096 Bulk Product 16f4190c Books $858.21 317 2.4 22 BULK-ff76f068
11097 Bulk Product 3e43cb31 Electronics $656.74 72 0.8 7 BULK-7cd2b11a
11098 Bulk Product 83260184 Electronics $317.53 73 2.8 79 BULK-0a3d566d
11099 Bulk Product d37733ce Home & Garden $216.01 212 4.8 29 BULK-7ed809c1
11100 Bulk Product a4341689 Home & Garden $788.47 269 2.3 5 BULK-73c369ec
11101 Bulk Product be8f64df Sports & Outdoors $991.61 381 3.4 69 BULK-7944b61b
11102 Bulk Product 82bc09b4 Books $203.54 173 4.1 52 BULK-ef7b0fb8
11103 Bulk Product 63f9037e Toys & Games $629.16 275 1.6 30 BULK-823fdd7e
11104 Bulk Product e8450642 Clothing $229.73 185 0.4 32 BULK-96f5bd54
11105 Bulk Product ce27c79e Clothing $216.20 23 2.8 30 BULK-d5811b06
11106 Bulk Product 4bc1af77 Toys & Games $314.93 207 1.7 28 BULK-f07800fb
11107 Bulk Product 8ceaadee Books $734.43 160 0.8 46 BULK-980dd3c8
11108 Bulk Product c6d9e179 Sports & Outdoors $286.31 458 0.5 9 BULK-9a226394
11109 Bulk Product 9bc79dac Home & Garden $872.24 264 4.0 43 BULK-d330f59e
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