title: System get stuck when filtered by DateTime in .Net MVC
body: <p>I have a function which generates the list of workorders:</p>
  <pre><code> public async Task&lt;Object&gt; GetAllWorkOrdersForUserAsync(string from,string to, int start, int length)
          {
  
                  IQueryable&lt;ReportWorkOrderViewModel&gt; resp;
            
                  resp = (from wo in _dbContext.WorkOrders
                          join woc in _dbContext.WorkOrderCategory on wo.WorkOrderCategoryId equals woc.Id
                          join sc in _dbContext.ServiceClients on wo.ServiceClientId equals sc.Id
                          join usr in _dbContext.Users on wo.UserId equals usr.Id into user
                          from uur in user.DefaultIfEmpty()
                          join contractor in _dbContext.Users on wo.ContractorId equals contractor.Id into contr
                          from contor in contr.DefaultIfEmpty()
                          select new ReportWorkOrderViewModel
                          {
                              Id = wo.Id,
                              WorkOrderType = woc.Name,
                              CustomerName = sc.FirstName + &quot; &quot; + sc.LastName,
                              CustomerAccount = wo.ServiceClientId,
                              AppointmentDate = wo.StartDateTime.ToString(),
                              IsHiring = (userId == wo.UserId),
                              CreatedAtDate = wo.CreatedAt.ToString(),
                              CreatedAtTime = wo.CreatedAt.ToString(),
                              CreatedBy = uur != null ? (uur.CompanyName != string.Empty ? uur.CompanyName : uur.ContactFirst + &quot; &quot; + uur.ContactLast) : string.Empty,
                              AssignedTechnician = contor != null ? (contor.ContactFirst + &quot; &quot; + contor.ContactLast) : string.Empty,
                              AppointmentTime = wo.StartDateTime.ToString(),
                              City = sc.City,
                              State = sc.State,
                              TicketStatus = wo.Status,
                              CompletionNote = wo.WorkPerformedDetail,
                              ClientsNote = wo.CustomerNotes,
                              TechStatus = wo.TechStatus == TechnicianStatus.Arrived ? &quot;Arrivied&quot; : wo.TechStatus == TechnicianStatus.OnTheWay ? &quot;On The Way&quot; : &quot;Init&quot;,
                          });
  
  
              int totalRows = resp.Count();
  
              
              if (!string.IsNullOrEmpty(from) &amp;&amp; !string.IsNullOrEmpty(to))
              {
                  try
                  {
                      DateTime fromDate = DateTime.Parse(from);
                      DateTime toDate = DateTime.Parse(to);
  
                     resp = resp.AsEnumerable().Where(d =&gt; Convert.ToDateTime(d.AppointmentDate) &gt;= fromDate &amp;&amp; Convert.ToDateTime(d.AppointmentDate) &lt;= toDate).AsQueryable();
                  }
                  catch
                  {
                  }
              }
  
  
              int totalRowsAfterFiltering = resp.Count();
              //&lt;!--sorting--&gt;
              resp = resp.OrderBy(searchColumnName + &quot; &quot; + sortDirection);
              
             
              //&lt;!--paging--&gt;
              if (paginate)
              {
                  if (totalRowsAfterFiltering != totalRows)
                  {
                      resp = resp.Skip(start).Take(length);
                  }
                  else
                  {
                      resp = resp.Where(x =&gt; x.Id &gt;= start).Take(length);
                  }
              }
              var response = new
              {
                  data = resp,
                  recordsTotal = totalRows,
                  recordsFiltered = totalRowsAfterFiltering
              };
  
              return response;
          }
  
  </code></pre>
  <p>My ViewModel is</p>
  <pre><code> public class ReportWorkOrderViewModel
      {
          public int Id { get; set; }
          public string WorkOrderType { get; set; }
          public int CustomerAccount { get; set; }
          public string CustomerName { get; set; }
  
          private string appointmentDate;
          public string AppointmentDate { get =&gt; appointmentDate; set =&gt; appointmentDate = Convert.ToDateTime(value).ToString(&quot;MM/dd/yyyy&quot;); }
          private string appointmentTime;
          public string AppointmentTime { get =&gt; appointmentTime; set =&gt; appointmentTime = Convert.ToDateTime(value).ToString(&quot;HH:mm tt&quot;); }
          public string CreatedBy { get; set; }
  }
  </code></pre>
  <p>The above function works fine and generates all the list when there no value for From and To. The total items in the list are 6-7000, but when i need the list  of data filtering through date and time. My System gets stuck in <code>int totalRowsAfterFiltering = resp.Count();</code> this part of code for 15-20second and finally populated 2/3 data only. But When I don't filter by date the list is executed in 2 second. What is the problem here?</p>