Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

36 ms

Page Size

25

Current Page

974 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 974 Results Showing 24326 - 24350 of 24441

ID Name Category Price Stock Rating Reviews SKU
24885 Bulk Product 7c208281 Electronics $511.40 19 1.8 71 BULK-46917734
24886 Bulk Product b885f912 Toys & Games $622.38 78 3.5 15 BULK-63e528aa
24887 Bulk Product aa8f0bf3 Home & Garden $506.95 1 2.9 76 BULK-84f88aef
24888 Bulk Product 06694a37 Home & Garden $392.39 173 4.1 76 BULK-ba6c078f
24889 Bulk Product cb72b7ef Clothing $261.98 73 0.0 64 BULK-e2b73fab
24890 Bulk Product 648a255b Electronics $117.03 275 4.0 97 BULK-4880969f
24891 Bulk Product c9f10c5e Books $873.91 307 0.6 3 BULK-d5e29b00
24892 Bulk Product 37830293 Toys & Games $599.91 54 2.4 68 BULK-bcf6d506
24893 Bulk Product 81e9f282 Clothing $885.24 424 4.9 82 BULK-2fa4d963
24894 Bulk Product 9e2552de Home & Garden $640.97 83 4.1 17 BULK-5a07a171
24895 Bulk Product c2fa79dd Sports & Outdoors $884.74 10 4.6 64 BULK-f346440f
24896 Bulk Product bc67e942 Electronics $460.08 409 0.9 3 BULK-5e14591d
24897 Bulk Product c0612917 Home & Garden $227.43 456 2.4 61 BULK-22921362
24898 Bulk Product 4a0f162b Sports & Outdoors $457.71 333 2.8 10 BULK-7fb04123
24899 Bulk Product be2ee416 Home & Garden $812.17 267 2.6 44 BULK-fdea0fa9
24900 Bulk Product 29a44ec2 Home & Garden $62.33 148 3.5 68 BULK-8d768aca
24901 Bulk Product e55c11dc Home & Garden $404.47 294 3.7 42 BULK-27fd7543
24902 Bulk Product 6e9736a6 Books $837.97 398 3.8 92 BULK-01e2bb70
24903 Bulk Product c661fec7 Sports & Outdoors $36.79 358 3.8 34 BULK-262fcff4
24904 Bulk Product 32b800e3 Sports & Outdoors $84.11 105 4.8 50 BULK-04ce65d9
24905 Bulk Product 59156065 Home & Garden $77.00 138 0.3 43 BULK-5f2c2e7c
24906 Bulk Product 11a230dc Home & Garden $650.77 474 1.9 12 BULK-b8b1bc2a
24907 Bulk Product ad38d0ca Books $335.18 419 1.9 87 BULK-1ac7c77c
24908 Bulk Product cf3024ab Books $586.30 90 0.1 91 BULK-a963d86a
24909 Bulk Product bef80398 Books $73.47 87 5.0 53 BULK-188df0c0
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