-4

I have been using this example for my code. http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application My issue is in controller I simply cannot afford to make a call to database 1000 times if there are 1000 pages. How can i store my list somewhere in controller or model and use that when calling this students has to be stored somewhere.

return View(students.ToPagedList(pageNumber, pageSize));
  • 3
    To clarify, are you saying you can't afford one DB call per request? – Jon Brian Skog Dec 03 '15 at 18:00
  • Then store it in a list and call `cachedList.Skip(n).Take(m)`. – Jasen Dec 03 '15 at 18:10
  • I can afford to make one call and save it as List somewhere and then use that list for paging but everytime i switch pages i cannot make database calls. Yes How can i stored cachedList. Is it possible to store in controller or model? – DoJo Developer Dec 03 '15 at 18:19
  • You can use the `Session["key"]` store. – Jasen Dec 03 '15 at 18:26
  • Thank you I can store it in session and reuse it. :) – DoJo Developer Dec 03 '15 at 18:35
  • Now i am using Session to store around 7 million records and whenever i make a request for 7 million session expires or becomes null and nothing is stored. – DoJo Developer Dec 03 '15 at 20:31
  • So the trade-off you need to make is memory usage versus database calls. You can also consider sending the entire set to the client and paginate with javascript in the browser. – Jasen Dec 04 '15 at 17:25
  • There's critical information you are leaving out here if you need to cache 7M records. Why can't the original query be more selective? Perhaps you should look to [optimize your original query](http://stackoverflow.com/questions/758186/how-to-get-n-rows-starting-from-row-m-from-sorted-table-in-t-sql)? – Jasen Dec 04 '15 at 17:43
  • I have tried paginating using javascript on client but to send all data to client takes more than 30 minutes (considering 7 Million Records) also query runs in around 15 seconds rest is sending that data to page. When i select range for more than 70K records and I switch page it shows this error:This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet. But i am not even using JSon for return i am sending dataset to partialview only. – DoJo Developer Dec 04 '15 at 20:45

1 Answers1

0

MSDN: Caching Application Data

You need to use caching. Pay careful attention to when you invalidate the cache. If the data updates often enough caching may not actually help much.