As per the profiler below, even with lazy loading being disabled, my query is taking a long time to return results:

Here s my query:

Here is my repository, where I am doing something ridiculous, taking only ONE record:

Questions:
-
Could someone tell me what would be the correct procedure to take say, 100 records and return them as fast as possible so the user will not have to wait long (while using the Unit of Work / Repository pattern)?
-
How would EF know how to paginate this info to a grid so the next batch of 100 records are available to the user, and the next batch, and so on?
I do not understand if I have .Take(1) why is the profiler returning 73,722 rows?
Your
dbSet.ToList()is causing the LINQ-to-Entities query to execute (and it says “please load the whole table from the database into memory”), not yourTake(1). This is applied to the already loaded result, not to the database query.You just need to change the order:
This would query for only one element in the database (using
TOP 1in SQL). To get the next records for paging you can useSkip(together withTake), for example: