I have a question regarding paging using linq concept.
I use the following way to fetch data:
Code: Select all
public List ListPage(int pageSize, int page)
{
return dataCtx.SomeTable.Skip(page * pageSize).Take(pageSize).ToList();
}
Code: Select all
for (int i = 0; i < 1000; i++)
{
service.ListPage(100, i);
}
Code: Select all
for (int i = 0; i < 1000; i++)
{
service.ListPage(100, 1000 - i);
}
After investigation, one for-loop cycle in the second test takes approximately the same time, regardless the value of variable 'i' (bit less for large values of 'i').
But this is not true for the first test. One for-loop cycle for small values of 'i' takes same time as in the second case. But when 'i' grows, elapsed time for one for-loop cycle grows as well. For large values of 'i', it takes the same time as to fetch all data from the table.
Moreover, if I change the range for 'i' in the first test to
Code: Select all
for (int i = 100; i < 1000; i++)
How can I ensure the same time consumption of one for-loop cycle in the first test when 'i' is in the range
Code: Select all
for (int i = 0; i < 1000; i++)
Thank you for reply.