Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF using skip and take on stored procedure

How does Skip() and Take() work in Entity Framework when calling a stored procedure? I can't access sql profiler to check, but I want to make sure I optimize the amount of data sent between servers.

Say I have the following code, where MyStoredProcedure returns 1000+ rows.

List<MyComplex_Result> myComplexList = db.MyStoredProcedure()
    .Skip(50)
    .Take(10);

Will the Take(10) make sure that only 10 of those rows are sent from the database server to the web server, or will all 1000+ rows be sent (though only 10 would be sent to the client)?

like image 326
The Jonas Persson Avatar asked Oct 29 '22 08:10

The Jonas Persson


1 Answers

I did encounter such requirements before. Originally, my option was to use stored procedure, but when I realize that data could be thousands, using SP no longer became applicable. Here are the two things I did to do this:

  1. I created a view where the result of SP is there. Of course, this contains all the records without filter yet. I used that view to manipulate the records via EF where Take and Skip is alreay applicable.
  2. I stick to SP. What I did is to design the SP to allow receiving Take and Skip Count. I created the SP as string the use sp_executesql.
like image 54
asteriskdothmg Avatar answered Nov 09 '22 07:11

asteriskdothmg