I use this method to get each page of data from EF:
public IEnumerable<MyObj> GetByPage(int page, int perPage)
{
return context.MyObj.Skip((page - 1) * perPage).Take(perPage);
}
I want to know ;would this code fetch all rows of MyObj and store in memory and then will Skip and Take or all of above code will translate to SQL command?
If all first will store in memory,How can I use LINQ to entity to not to use memory to Skip and Take?
IQueryable<MyObj>too so that the calling code can add additional query operations to be performed in the backing data store (whereasIEnumerable<MyObj>will cause those operations to be performed by the CLR, after the query returns from the data store).Skip()operation would force all of the skipped-over records to be fetched and then discarded, one-by-one. TheTake()operation will dispose of its enumerator after it has fetched the specified number of rows, so the rows after those you fetch may not necessarily be fetched from disk by the database server, nor returned to the database client in your application. (But they might, depending on the database and client library implementations.)