Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

25

Current Page

693 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 693 Results Showing 17301 - 17325 of 24441

ID Name Category Price Stock Rating Reviews SKU
17860 Bulk Product 5b44019c Toys & Games $706.14 440 2.2 2 BULK-9d0ad48c
17861 Bulk Product f83319f1 Home & Garden $46.39 257 2.2 99 BULK-c958224d
17862 Bulk Product 838bfecd Home & Garden $491.88 93 3.7 42 BULK-8659e298
17863 Bulk Product 0e947519 Electronics $607.05 390 2.4 79 BULK-d9d48a22
17864 Bulk Product 3e0c9d61 Toys & Games $965.33 237 1.3 62 BULK-8a73b5ec
17865 Bulk Product 6c760210 Books $586.74 49 0.0 27 BULK-50ad3f92
17866 Bulk Product f1fc5451 Books $185.20 149 4.0 80 BULK-6dd2f7a8
17867 Bulk Product 297a1ee0 Home & Garden $364.96 275 1.2 67 BULK-7c966de5
17868 Bulk Product 4e34740b Clothing $493.50 93 4.1 41 BULK-25294db1
17869 Bulk Product 6da48805 Sports & Outdoors $711.87 125 4.3 1 BULK-363c48b0
17870 Bulk Product b250caa6 Home & Garden $774.99 483 4.5 21 BULK-4131d061
17871 Bulk Product a7c0d0e4 Books $903.37 291 3.9 74 BULK-1b883563
17872 Bulk Product c652afe9 Clothing $234.56 475 2.2 32 BULK-cb25d384
17873 Bulk Product 02c68a6d Clothing $204.53 109 0.9 80 BULK-cc4554f1
17874 Bulk Product d742ce36 Sports & Outdoors $387.62 5 3.5 25 BULK-0f118da5
17875 Bulk Product 829f339b Home & Garden $590.01 468 0.0 6 BULK-247fefbb
17876 Bulk Product 00572ab4 Home & Garden $371.05 164 0.3 86 BULK-33562654
17877 Bulk Product 63a56078 Sports & Outdoors $388.21 228 4.2 55 BULK-8a556899
17878 Bulk Product 0ec7219d Books $123.39 301 0.6 22 BULK-89bdb789
17879 Bulk Product 950b6c0e Home & Garden $698.12 474 1.2 79 BULK-72de8335
17880 Bulk Product b054bd1b Home & Garden $171.33 199 0.5 28 BULK-24e4e4cb
17881 Bulk Product e07fb92e Clothing $386.56 101 3.4 49 BULK-0bdc5940
17882 Bulk Product bb23c63f Toys & Games $667.15 177 3.4 10 BULK-e5965578
17883 Bulk Product cee71bca Clothing $457.16 27 2.4 40 BULK-732f2872
17884 Bulk Product 663ebee4 Books $934.82 125 3.9 50 BULK-f6e489fd
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