Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

334 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 334 Results Showing 8326 - 8350 of 24441

ID Name Category Price Stock Rating Reviews SKU
8885 Bulk Product c6ae84fd Home & Garden $148.02 244 4.8 39 BULK-d3cf5751
8886 Bulk Product 26dd139a Toys & Games $298.73 436 1.3 64 BULK-cb3d377b
8887 Bulk Product ef915c90 Home & Garden $622.10 355 3.6 84 BULK-e21eb274
8888 Bulk Product b9a927f0 Sports & Outdoors $292.62 113 3.3 76 BULK-cc1d6e23
8889 Bulk Product 9e3f7944 Toys & Games $431.68 443 4.6 38 BULK-40de055a
8890 Bulk Product b1a2b4a7 Electronics $640.67 108 4.3 13 BULK-d30972b0
8891 Bulk Product d3530c80 Clothing $19.90 224 3.8 11 BULK-aabfaff1
8892 Bulk Product c6204b7f Clothing $757.73 448 1.3 54 BULK-1e4423c5
8893 Bulk Product c86f71d6 Sports & Outdoors $570.91 106 1.8 0 BULK-79eb9b41
8894 Bulk Product 8f6ae760 Toys & Games $841.54 179 4.7 1 BULK-e190d92a
8895 Bulk Product b988968f Clothing $915.89 162 2.4 15 BULK-872cb765
8896 Bulk Product 6a0c0a09 Books $207.28 72 2.3 82 BULK-39affecb
8897 Bulk Product 149da02e Electronics $21.52 165 4.0 7 BULK-ea80330a
8898 Bulk Product 5f7d3ade Home & Garden $1,002.90 167 1.6 80 BULK-4b3d96bb
8899 Bulk Product b6fc5199 Sports & Outdoors $270.08 304 1.7 77 BULK-2adc8399
8900 Bulk Product eb9000d5 Books $989.11 458 1.2 35 BULK-7e321538
8901 Bulk Product 77036682 Books $788.77 161 3.4 90 BULK-d5dcf6bf
8902 Bulk Product 8aeb33b0 Electronics $333.22 168 4.8 73 BULK-fa527abd
8903 Bulk Product 22d3613d Home & Garden $764.38 139 3.7 62 BULK-6b490c02
8904 Bulk Product c933f8ef Electronics $469.74 129 0.1 13 BULK-6ee157ad
8905 Bulk Product 5c41a55c Sports & Outdoors $895.48 377 3.4 30 BULK-a3da270c
8906 Bulk Product fba6bde7 Clothing $293.70 132 1.8 96 BULK-f39182b3
8907 Bulk Product 702f3d56 Home & Garden $843.48 225 1.6 15 BULK-f4f1c2d8
8908 Bulk Product 1dc9cc4b Home & Garden $325.48 150 4.2 19 BULK-9d498c42
8909 Bulk Product 5a818079 Electronics $630.58 393 0.8 27 BULK-a84f0fe7
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