Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

54 ms

Page Size

25

Current Page

454 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 454 Results Showing 11326 - 11350 of 24441

ID Name Category Price Stock Rating Reviews SKU
11885 Bulk Product 3255ca83 Electronics $91.77 96 3.9 47 BULK-511f3a55
11886 Bulk Product d1044c77 Toys & Games $306.79 245 2.1 62 BULK-5329bffd
11887 Bulk Product 3a8fe310 Toys & Games $11.14 68 1.7 77 BULK-5533dbcd
11888 Bulk Product 4712e02c Sports & Outdoors $718.09 41 4.2 78 BULK-6ad52ff7
11889 Bulk Product b7704fbb Electronics $744.52 382 4.5 53 BULK-10c3c584
11890 Bulk Product 37dd0be5 Sports & Outdoors $700.00 160 1.3 2 BULK-2d397463
11891 Bulk Product a72a8098 Home & Garden $612.87 186 0.8 35 BULK-4c49c57f
11892 Bulk Product d83373c0 Sports & Outdoors $334.50 433 1.2 32 BULK-e1bc5715
11893 Bulk Product 47728fba Toys & Games $385.74 214 0.4 80 BULK-228c1ef3
11894 Bulk Product 0b3d0cd6 Clothing $127.15 348 1.9 44 BULK-6239e063
11895 Bulk Product 1b36ddc8 Sports & Outdoors $123.67 423 0.6 76 BULK-047ae241
11896 Bulk Product 7b19bf1f Clothing $873.68 129 0.0 94 BULK-4179704d
11897 Bulk Product 0ebac209 Clothing $509.12 433 1.4 38 BULK-858cca3d
11898 Bulk Product ee88e3ec Books $231.01 286 0.7 14 BULK-e7a786b9
11899 Bulk Product 9c64a2fc Home & Garden $576.46 101 4.1 31 BULK-da9e92f5
11900 Bulk Product 6315bbc9 Books $300.69 416 3.1 93 BULK-be0ab1c7
11901 Bulk Product ba8b6510 Toys & Games $517.35 102 1.2 41 BULK-a28a76e7
11902 Bulk Product 4238a002 Sports & Outdoors $231.94 321 0.8 60 BULK-0e3d5203
11903 Bulk Product 7e639a02 Home & Garden $564.86 311 3.6 11 BULK-0d400cc3
11904 Bulk Product 5b5d0036 Electronics $917.77 374 0.5 58 BULK-89358082
11905 Bulk Product eaddfd05 Books $704.98 3 4.9 14 BULK-b8c48f62
11906 Bulk Product 26e3d499 Books $605.64 303 4.9 52 BULK-38558919
11907 Bulk Product 399f90f0 Books $540.02 245 4.0 10 BULK-7b365661
11908 Bulk Product 24ac614d Books $282.57 4 2.8 16 BULK-f1f1248f
11909 Bulk Product cb02182b Clothing $710.60 148 0.7 44 BULK-f44f53da
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