I have a ASP.NET MVC 4 application and I'm using EF. I have a table and a SQL view(the view displays rows from this table plus some unimportant data(~ 1000 records)) with ~ 400.000 records. When I display the data in EF it takes 25 seconds
MVCAppEntities db = new MVCAppEntities();
public ActionResult Index()
{
return View(db.vvItem.OrderBy(n => n.Code).Skip(20).Take(40).ToList());
}
In SQL Server Management Studio this query takes 0-1 seconds
select code, quantity, name, price
from (
select *,
row_number() over(order by code) as rn
from vvItem
) as T
where T.rn between 20 and 40
Q : Why is the EF query so slow ? should I make a SP to do the Skip and Take ?