简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM