I have currently in a table about 90k rows. And it’s will grow up about 1kk ~ 5kk before i execute a clean up and put all rows in a “historical table”. So, when i run this following query (MyEntities is a ObjectSet):
MyEntities.Skip(amount * page).Take(amount).ToList();
This query takes about 1.2s… but when i run this following query with OrderBy and ThenBy:
MyEntities.OrderBy(b => b.Day).ThenBy(b => b.InitialHour).Skip(amount * page).Take(amount).ToList();
This query takes about 5.7s. There is a way to optimize the second query?
A few suggestions:
DayandInitialHourare indexed.EDIT: Okay, so it looks like
MyEntitiesis actually declared asIEnumerable<MyEntity>, which means everything will be done in-process… all your LINQ calls will be viaEnumerable.Selectetc, rather thanQueryable.Selectetc. Just change the declared type ofMyEntitiestoIQueryable<MyEntity>and watch it fly…