title: LINQ query performance issue when fetching data from db in MVC Razor
body: <p><strong>Problem Statement:</strong>
  I'm trying to bind Multi-table data from db to view using Linq query which is taking more time.I'm having around 10000 records in db.Someone suggested to use the IQueryable instead of IEnumerable,but does it affect my current code(In both View and Controller)?? Or without using that can I accomplish this?? </p>
  
  <p><em>What I should do in-order to increase the performance of loading the result??</em>
  <em>What I'm doing wrong??
  <strong>Please suggest me some better way of doing this...</em></strong></p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>public ActionResult Index()
      {
          var result = (from pr in db.Prod.AsEnumerable()
                        join s in db.Shift.AsEnumerable() on pr.Shift equals s.ShiftID
                        join m in db.Module.AsEnumerable() on pr.Module equals m.ModuleID
                        select new GlobalModel()
                        {
                            prodModelIndex = pr,
                            prodModel = prodModel,
                            shiftModel = s,
                            moduleModel = m,
                            ddlShift = objTransactionGeneralController.GetAllShift(),
                            ddlModule = objTransactionGeneralController.GetAllModule()
  
                        }).ToList();
      return PartialView(result);
  
      }
  
  
  
  
  
     public TransGeneralModel GetAllModule()
      {
  
          objTransGeneralModel.ddlModule = (from m in db.Module.AsEnumerable()
                                             select new SelectListItem
                                             {
                                                 Value = m.ModuleID.ToString(),
                                                 Text = m.ModuleName,
                                             }).ToList();
  
  
          return objTransGeneralModel;
      }
  
      public TransGeneralModel GetAllShift()
      {
  
          objTransGeneralModel.ddlShift = (from s in db.Shift.AsEnumerable()
                                            select new SelectListItem
                                            {
                                                Value = s.ShiftID.ToString(),
                                                Text = s.ShiftName,
                                            }).ToList();
  
  
          return objTranGeneralModel;
      }
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>@model IEnumerable&lt;SIA.Models.Trans.GlobalModel&gt;
  
  @using GridMvc.Html
  
  @{
      Layout = "~/Views/Shared/_Layout.cshtml";
      ViewBag.Title = "Index";
  
      }
  
      &lt;link rel="stylesheet" href="@Url.Content("~/Content/jquery.dataTables.min.css")"&gt;
      &lt;script src="@Url.Content("~/Scripts/jquery-2.1.1.min.js")"&gt;&lt;/script&gt;
  
  
      &lt;h2&gt;Details&lt;/h2&gt;
      &lt;hr /&gt;
  
      &lt;div style="width: 1000px; padding-left: 70px"&gt;
          @Html.Partial("Create")
          &lt;br /&gt;
      &lt;/div&gt;
  
      &lt;h5 class="pull-right"&gt;
          &lt;b class="fa fa-keyboard-o" style="color: blue"&gt;&lt;/b&gt;
          @Ajax.ActionLink("Edit", "ProdEdit", "Prod", new { }, new AjaxOptions
      {
          InsertionMode = InsertionMode.Replace,
          UpdateTargetId = "prod-details",
          HttpMethod = "GET",
      }, new { style = "color:blue" })
      &lt;/h5&gt;
  
      &lt;br /&gt;
      @using (Html.BeginForm())
      {
          @Html.AntiForgeryToken()
          @Html.ValidationSummary(true)
          if (Model.FirstOrDefault().prodModelIndex != null)
          { 
  
          &lt;div id="prod-details"&gt;
              &lt;table class="table table-striped" id="tblProdDetails"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
  
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.FirstOrDefault().prodModelIndex.ProdID)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.FirstOrDefault().prodModelIndex.Date)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.FirstOrDefault().prodModelIndex.Module)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.FirstOrDefault().productionModelIndex.Shift)
                          &lt;/th&gt;
  
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.FirstOrDefault().prodModelIndex.Hour)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.DisplayNameFor(model =&gt; model.FirstOrDefault().prodModelIndex.Output)
                          &lt;/th&gt;
  
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      @foreach (var item in Model)
                      {
                          &lt;tr id="customer-row-@item.prodModelIndex.ProdID"&gt;
  
  
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.prodModelIndex.ProdID)
                              &lt;/td&gt;
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.prodModelIndex.Date)
                              &lt;/td&gt;
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.moduleModel.ModuleName)
                              &lt;/td&gt;
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.shiftModel.ShiftName)
                                  @Html.HiddenFor(modelItem =&gt; item.prodModelIndex.Shift)
                              &lt;/td&gt;
  
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.prodModelIndex.Hour)
                              &lt;/td&gt;
                              &lt;td&gt;
                                  @Html.DisplayFor(modelItem =&gt; item.prodModelIndex.Output)
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      }
                  &lt;/tbody&gt;
              &lt;/table&gt;
  
          &lt;/div&gt;
          }
      }
  
      &lt;script&gt;
  
          $(document).ready(function () {
  
              $('#tblProdDetails').dataTable({
                  "order": [[1, "desc"], [3, "asc"]]
  
              });
  
          });
      &lt;/script&gt;
  
      @section Scripts {
          @Scripts.Render("~/bundles/jqueryval")
          @Scripts.Render("~/Scripts/jquery.dataTables.min.js")
          &lt;script type='text/javascript'&gt;
              $(function () {
                  $('.datepicker').datepicker({
                      format: "dd M yyyy",
                  }).on('changeDate', function (e) {
                      $(this).datepicker('hide');
                  });
              })
  
          &lt;/script&gt;
      }
  </code></pre>