I am currently using Entity Framework in an ASP.NET MVC 3 project.
And I am getting severe performance issues while looping through the records in the view to display them.
The data is being recieved quickly, so I know it’s not the connection to our remote oracle server and there are no lazy loaded relationships in the model I’m using, yet each record is taking 120-300ms to process a simple 3 field output with an action link.
Currently it takes over 3 minutes to load the page with 800ish records.
I’ve tried tweaking with configuration options but none seem to help.
Anyone has any ideas?
edit: controller code
readonly OracleSampleManagerContext db = new OracleSampleManagerContext();
public virtual ActionResult Index()
{
var spList = db.SamplePoints.OrderBy(e=>e.Id).ToList();
return View(MVC.Reports.Views.SamplePointList, spList);
}
<h2>
Selection By Sample Point
</h2>
<table>
@foreach (var sp in Model)
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
<tr>
<td>@Html.ActionLink(sp.Id, MVC.Reports.Results(sp.Id))</td>
<td>@sp.Description</td>
<td>@sp.PointLocation</td>
<td>@sw.ElapsedMilliseconds</td>
</tr>
sw.Stop();
sw.Reset();
}
</table>
Example:
0200 72" Sewer to river - Once through cooling water OUTFALLS 346ms
0400 66" Sewer to river - Combined effluent OUTFALLS 347ms
0500 54" Sewer to river - Once through cooling water OUTFALLS 388ms
06-AI-18 TBA in Water IB2 228ms
06-AI-31 TBA in Water IB2 172ms
My guess is that
MVC.Reports.Results(sp.Id)does some sort of db lookup, and since you converted your model to a list before sending it to the view, you now have to hit the database again for each record Making a page of 800 records require 801 seperate trips to the database instead of one.Both of the above may require you to move the scope of your entities context from within the action out to the Controller.