I have a table of 200,000 record where I am getting only the top 10 using .Take() but it is taking about 10 seconds to get the data.
My question is: does the .Take() method get all the data from the database and filter the top 10 on the client side?
Here is my code:
mylist = (from mytable in db.spdata().OrderByDescending(f => f.Weight)
group feed by mytable.id into g
select g.FirstOrDefault()).Take(10).ToList();
spdata() is a function Import from stored procedure.
Thanks
The stored procedure probably returns a lot of data to the client which is very slow. You cannot remote a query to an sproc. That would be possible using a view or a table-valued function.
There’s no way to use an sproc in a query. You can only execute it by itself.
Your intention probably was to execute the
Take(10)on the server. For that to work you need to switch to an inline query, a view or a TVF.