Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paging with LINQ without sorting

I want to create paging with LINQ to entity (EF) ,I found Skip method but it is only supported for sorted input,so I think it will be slow in large amount of rows. Is any way to paging without sorting it first?

like image 774
Majid Avatar asked Dec 14 '25 05:12

Majid


1 Answers

A database is not obliged to return the set of records in same order, for a specific SQL query, without a specific order declared.

You may run the same query and first 10 records be different on each run. Database will execute this based on what is best for itself (what part of data is cached in memory, what parts changed before two executions of the same query and the like).

So regardless of what ORM you use, you have to specify in what order you want the data. And be sure you have a properly defined index for the field that you are ordering the records based on that.

like image 195
Kaveh Shahbazian Avatar answered Dec 15 '25 18:12

Kaveh Shahbazian