Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

936 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 936 Results Showing 23376 - 23400 of 24441

ID Name Category Price Stock Rating Reviews SKU
23935 Bulk Product cc1183e8 Electronics $188.80 449 2.0 35 BULK-22b7f8cd
23936 Bulk Product 6a787d54 Electronics $451.34 171 3.6 55 BULK-8bc66edd
23937 Bulk Product 6546d197 Sports & Outdoors $354.66 34 4.8 95 BULK-7806709e
23938 Bulk Product 4877482d Toys & Games $908.38 243 1.4 6 BULK-53c9475f
23939 Bulk Product 95abb079 Electronics $747.54 122 2.5 2 BULK-dc827493
23940 Bulk Product d0762267 Toys & Games $307.86 190 4.8 9 BULK-b49c60fc
23941 Bulk Product 8ebf335b Toys & Games $522.48 483 3.9 0 BULK-c99db6ab
23942 Bulk Product a3a55515 Home & Garden $12.27 433 3.8 99 BULK-051bc4cf
23943 Bulk Product ccc33847 Books $41.82 120 3.8 31 BULK-38d04c42
23944 Bulk Product 4b646ea9 Clothing $487.05 171 0.8 33 BULK-53c062ea
23945 Bulk Product 60bc49f2 Clothing $607.95 64 3.0 31 BULK-fedaf266
23946 Bulk Product b4a07250 Clothing $701.51 160 2.3 90 BULK-45f73ef6
23947 Bulk Product 563f52db Books $300.26 330 3.4 50 BULK-739a42f3
23948 Bulk Product 6e73bc99 Home & Garden $817.87 370 4.5 42 BULK-c56cb860
23949 Bulk Product 1afedd1a Home & Garden $675.35 90 4.8 4 BULK-b9b642b0
23950 Bulk Product 8161b0f8 Electronics $803.47 188 4.0 97 BULK-d7f11ff9
23951 Bulk Product 5dcb5a7f Sports & Outdoors $211.61 306 2.3 90 BULK-0e615546
23952 Bulk Product df6339dc Books $572.21 445 2.9 79 BULK-bdf6bfd7
23953 Bulk Product 0efb7c53 Sports & Outdoors $501.73 67 2.0 67 BULK-04d5c575
23954 Bulk Product c1ffb089 Electronics $581.04 75 2.4 0 BULK-140fe3a2
23955 Bulk Product 34b363b2 Home & Garden $121.33 283 0.8 17 BULK-c0e826a7
23956 Bulk Product 60409b3c Sports & Outdoors $26.62 264 0.7 27 BULK-6966e780
23957 Bulk Product 7ae1090b Home & Garden $126.95 60 2.8 35 BULK-7384669f
23958 Bulk Product c885133d Toys & Games $181.72 242 4.5 78 BULK-2da5e84c
23959 Bulk Product 576a965d Electronics $657.09 384 2.0 56 BULK-2b0dfa77
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