title: How would I speed up my asp.net mvc application?
body: <p>I'm currently working on a project where I must pull data from a database and display them onto tables in my view. I have all this working, but it takes about 10-15 seconds to load up the page. If possible I would like to decrease this time.</p>
  
  <p>I believe the problem lies with obtaining the information from the database. There are many items I pull from the database, and I believe there is possibly a better way of doing so.</p>
  
  <p>Controller:</p>
  
  <pre><code> public class HomeController : Controller
  {
      private RestoreDBEntities db = new RestoreDBEntities();
  
      public ActionResult Index()
      {
          W6ViewModel viewModel = new W6ViewModel();
          viewModel.engineers = db.W6ENGINEERS.OrderBy(w =&gt; w.Name).Include(w =&gt; w.W6CALENDARS).ToList();
          viewModel.tasks = db.W6TASKS.ToList();
  
          return View(viewModel);
      }
  
      public ActionResult Details(int? id)
      {
          if (id == null)
          {
              return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
          }
          W6ENGINEERS w6ENGINEERS = db.W6ENGINEERS.Find(id);
          if (w6ENGINEERS == null)
          {
              return HttpNotFound();
          }
          return View(w6ENGINEERS);
      }
  
      [HttpPost]
      public ActionResult Filter(FormCollection collection)
      {
          string city = collection["city"];
  
          W6ViewModel viewModel = new W6ViewModel();
          viewModel.engineers = db.W6ENGINEERS.Where(w =&gt; w.City == city).Include(w =&gt; w.W6CALENDARS).ToList();
          viewModel.tasks = db.W6TASKS.Where(w =&gt; w.City == city).Include(w =&gt; w.W6CALENDARS).ToList();
  
          return View("Index", viewModel);
      }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@model WebApplication1.ViewModel.W6ViewModel
  
  @{
      ViewBag.Title = "Dispatcher";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  
  &lt;section id="fields"&gt;
      &lt;h3 id="field_filter"&gt;&lt;strong&gt;Filters&lt;/strong&gt;&lt;/h3&gt;
      &lt;h3 id="field_engineer"&gt;&lt;strong&gt;Engineers&lt;/strong&gt;&lt;/h3&gt;
      &lt;h3 id="field_task"&gt;&lt;strong&gt;Tasks&lt;/strong&gt;&lt;/h3&gt;
  &lt;/section&gt;
  
  &lt;section id="filters"&gt;
      @using (Html.BeginForm("Filter", "Home", FormMethod.Post))
      { 
          &lt;input name="city" id="city" type="text" maxlength="15" title="City" value    ="City" style="color:#888;" 
           onfocus ="inputFocus(this)" onblur="inputBlur(this)" /&gt;
           &lt;input id="submit" type="submit" value="Submit" /&gt;`enter code here`
      }
   &lt;/section&gt;
  
   &lt;section id="engineers"&gt;
       &lt;table class="table-condensed table-striped"&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  Name
              &lt;/th&gt;
              &lt;th&gt;
                  Phone number
              &lt;/th&gt;
          &lt;th&gt;
              City
          &lt;/th&gt;
          &lt;th&gt;
              Region
          &lt;/th&gt;
          &lt;th&gt;
              Availability Factor
          &lt;/th&gt;
      &lt;/tr&gt;
  
          @foreach (var item in Model.engineers)
          {
              &lt;tr&gt;
                  &lt;td&gt;
                      @Html.ActionLink(item.Name, "Details", new { id = item.W6Key })
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.MobilePhone)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.City)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.Region)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.AvailabilityFactor)
                  &lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/table&gt;
  &lt;/section&gt;
  
  &lt;section id="work"&gt;
      &lt;table class="table-condensed table-striped"&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  Job ID
              &lt;/th&gt;
              &lt;th&gt;
                  Skills 
              &lt;/th&gt;
              &lt;th&gt;
                  Address
              &lt;/th&gt;
          &lt;/tr&gt;
  
      @foreach(var item in Model.tasks)
      {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.City)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.IsScheduled)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.IsPartsNotUsed)
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  </code></pre>
  
  <p></p>
  
  <p>Webconfig:</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;configuration&gt;
  &lt;configSections&gt;
  &lt;section name="entityFramework"   type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,  Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"  requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20140611092404.mdf;Initial Catalog=aspnet-WebApplication1-20140611092404;Integrated Security=True" providerName="System.Data.SqlClient" /&gt;
      &lt;add name="RestoreDBEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=T520-R9K0H1K\SQLEXPRESS;initial catalog=RestoreDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
       &lt;authentication mode="None" /&gt;
      &lt;compilation debug="true" targetFramework="4.5.1" /&gt;
      &lt;httpRuntime targetFramework="4.5.1" /&gt;
    &lt;/system.web&gt;
  
    &lt;system.webServer&gt;
      &lt;urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/&gt;
    &lt;/system.webServer&gt;
  
    &lt;system.webServer&gt;
      &lt;modules&gt;
        &lt;remove name="FormsAuthenticationModule" /&gt;
      &lt;/modules&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"    /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Thanks much in advance!</p>
  
  <p>EDIT:</p>
  
  <p>so after installing DotTrace, and using it to diagnose my project, it seems it is my calls to the database that are causing the long load times (my opinion, though I have no experience with DotTrace) </p>
  
  <p>I have added a screenshot, if anyone can confirm/propose a solution that would be great.</p>
  
  <p><img src="https://i.stack.imgur.com/fvrje.jpg" alt="DotTrace Snapshot upon running the project"></p>