Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

67 ms

Page Size

50

Current Page

170 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 170 Results Showing 8451 - 8500 of 24441

ID Name Category Price Stock Rating Reviews SKU
9010 Bulk Product 5c903a22 Electronics $492.97 86 0.8 39 BULK-7f1af46d
9011 Bulk Product 9b623c2a Books $320.42 172 0.6 53 BULK-55439da1
9012 Bulk Product 4c2b9ac8 Sports & Outdoors $694.33 367 2.5 23 BULK-e1683d53
9013 Bulk Product 86da08e3 Sports & Outdoors $961.45 158 1.1 70 BULK-92c2670b
9014 Bulk Product d608ccc1 Clothing $758.98 360 0.7 49 BULK-8051c7b0
9015 Bulk Product 51dbbd58 Books $574.76 373 1.7 52 BULK-e1f676d2
9016 Bulk Product 0f4e35b2 Clothing $572.68 270 3.9 8 BULK-dcb9833e
9017 Bulk Product bed243c4 Electronics $624.39 445 0.6 20 BULK-eba9f117
9018 Bulk Product 20ab5555 Clothing $325.00 193 1.3 87 BULK-66b53976
9019 Bulk Product c2fbbcb7 Electronics $932.38 143 0.6 90 BULK-b7f600c9
9020 Bulk Product 7494fe49 Electronics $615.43 324 0.7 47 BULK-9e24b17d
9021 Bulk Product 642180d6 Clothing $1,004.82 291 3.3 45 BULK-9943309d
9022 Bulk Product 03f9d4e3 Toys & Games $538.75 377 1.6 50 BULK-64ee3d4e
9023 Bulk Product 1675d404 Home & Garden $692.01 164 1.6 76 BULK-878633e1
9024 Bulk Product 73791d18 Toys & Games $578.92 344 4.8 67 BULK-2aa6c7bd
9025 Bulk Product 75404ee2 Clothing $949.74 407 4.0 35 BULK-4d4a6b13
9026 Bulk Product 42e875b6 Toys & Games $55.25 425 4.6 4 BULK-81eea77b
9027 Bulk Product 0e797604 Home & Garden $648.69 432 2.4 81 BULK-3a52e887
9028 Bulk Product f7415cbd Sports & Outdoors $959.37 22 4.3 77 BULK-07ee33df
9029 Bulk Product 4ca21f15 Books $948.10 190 4.3 24 BULK-90ff20d7
9030 Bulk Product 5e77bae1 Home & Garden $458.81 261 1.4 87 BULK-122173e0
9031 Bulk Product 699d8edd Sports & Outdoors $634.73 137 1.5 74 BULK-77e99d9e
9032 Bulk Product bc2f2e34 Electronics $850.66 78 0.3 33 BULK-5df53b69
9033 Bulk Product 2d0c40db Home & Garden $663.91 218 0.5 33 BULK-6f265e75
9034 Bulk Product 554ef9e3 Clothing $592.03 8 3.7 68 BULK-d5fa57bd
9035 Bulk Product 1f38760a Clothing $231.88 173 2.1 66 BULK-c4b2bc9a
9036 Bulk Product 46814be6 Sports & Outdoors $192.60 152 0.1 84 BULK-b2a01495
9037 Bulk Product 00463da1 Clothing $730.23 263 1.5 49 BULK-99fcdfbb
9038 Bulk Product 74d1353c Books $356.30 74 4.5 25 BULK-7c23af0c
9039 Bulk Product 12f7fd31 Home & Garden $569.63 133 2.6 34 BULK-6b25084f
9040 Bulk Product f49b3def Clothing $409.00 201 2.7 99 BULK-8a13749c
9041 Bulk Product 3104670d Home & Garden $880.65 194 4.6 45 BULK-574535bb
9042 Bulk Product 946c4a5a Clothing $667.16 489 2.5 84 BULK-f1fdd1d0
9043 Bulk Product 2a9917f4 Home & Garden $202.18 448 2.8 68 BULK-25619077
9044 Bulk Product a0f59b9c Home & Garden $482.08 391 4.8 46 BULK-67a5b654
9045 Bulk Product a5777bb5 Books $974.22 304 0.1 66 BULK-82777824
9046 Bulk Product 09e22686 Clothing $946.01 20 5.0 95 BULK-ac32683f
9047 Bulk Product 20d2732c Clothing $789.50 187 3.7 19 BULK-a6c4fd91
9048 Bulk Product c1574c84 Clothing $728.92 135 4.9 13 BULK-fee4f3a7
9049 Bulk Product 66eae88e Toys & Games $18.57 22 0.3 8 BULK-a8238e2c
9050 Bulk Product b16a5156 Books $41.04 142 2.5 35 BULK-5de7e27a
9051 Bulk Product 47c104ce Sports & Outdoors $390.12 450 1.1 18 BULK-8e35f653
9052 Bulk Product 8280b583 Electronics $752.62 293 2.3 71 BULK-ec3659ba
9053 Bulk Product 5f388cc3 Toys & Games $402.84 50 0.3 90 BULK-48e458a9
9054 Bulk Product 1c234c0c Books $157.59 462 4.8 42 BULK-b139cb04
9055 Bulk Product 571cff46 Sports & Outdoors $908.23 287 1.1 1 BULK-f857b199
9056 Bulk Product a5be8374 Sports & Outdoors $710.75 263 3.2 95 BULK-c43f1ee7
9057 Bulk Product 681c110d Books $440.82 9 2.7 28 BULK-876518ca
9058 Bulk Product 36cbf715 Clothing $788.56 497 1.7 69 BULK-ea528f00
9059 Bulk Product 3d560853 Toys & Games $775.55 241 1.2 86 BULK-0e9c8955
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