I'd like to get a record's row number inside a huge list of records from a table, using Entity Framework 6.
I tried this code:
//var currentUser = my record
var orderedUsers = dbContext.User.OrderByDescending(u => u.Age).ToList();
var userIndex = orderedUsers.IndexOf(currentUser);
The ToList()
method crashes with a timeout, because I assume that this methods loads the whole list in memory.
How can I get this row number using a simpler method with Linq (so, without ToList
or mounting everything in memory) ?
For information, my goal is to get a range of record from a start index to another index. Here's the code I wrote to do this:
var result = orderedUsers.Skip(userIndex).Take(30).ToList();
Thanks