title: The method 'OrderBy' must be called before the method 'Skip' Exception
body: <p>I was trying to implement the <code>jQgrid</code> using <code>MvcjQgrid</code> and i got this exception. </p>
  
  <pre><code>System.NotSupportedException was unhandled by user code
    Message=The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.
  </code></pre>
  
  <p>Though OrdeyBy is used before Skip method why it is generating the exception? How can it be solved?</p>
  
  <p>I encountered the exception in the controller:</p>
  
  <pre><code>public ActionResult GridDataBasic(GridSettings gridSettings)
          {          
              var jobdescription = sm.GetJobDescription(gridSettings);
              var totalJobDescription = sm.CountJobDescription(gridSettings);
  
              var jsonData = new
              {
                  total = totalJobDescription / gridSettings.PageSize + 1,
                  page = gridSettings.PageIndex,
                  records = totalJobDescription,
                  rows = (
                      from j in jobdescription
                      select new
                      {
                          id = j.JobDescriptionID,
                          cell = new[] 
                      { 
                          j.JobDescriptionID.ToString(), 
                          j.JobTitle,
                          j.JobType.JobTypeName,
                          j.JobPriority.JobPriorityName,
                          j.JobType.Rate.ToString(),
                          j.CreationDate.ToShortDateString(),
                           j.JobDeadline.ToShortDateString(),
  
                      }
                      }).ToArray()
              };
              return Json(jsonData, JsonRequestBehavior.AllowGet);
          }
  </code></pre>
  
  <p><strong>GetJobDescription Method</strong> and <strong>CountJobDescription Method</strong></p>
  
  <pre><code>public int CountJobDescription(GridSettings gridSettings)
          {
              var jobdescription = _dataContext.JobDescriptions.AsQueryable();
  
              if (gridSettings.IsSearch)
              {
                  jobdescription = gridSettings.Where.rules.Aggregate(jobdescription, FilterJobDescription);
              }
              return jobdescription.Count();
          }
  
          public IQueryable&lt;JobDescription&gt; GetJobDescription(GridSettings gridSettings)
          {
              var jobdescription = orderJobDescription(_dataContext.JobDescriptions.AsQueryable(), gridSettings.SortColumn, gridSettings.SortOrder);
  
              if (gridSettings.IsSearch)
              {
                  jobdescription = gridSettings.Where.rules.Aggregate(jobdescription, FilterJobDescription);
              }
  
              return jobdescription.Skip((gridSettings.PageIndex - 1) * gridSettings.PageSize).Take(gridSettings.PageSize);
          }
  </code></pre>
  
  <p>And Finally <strong>FilterJobDescription and OrderJobDescription</strong> </p>
  
  <pre><code>private static IQueryable&lt;JobDescription&gt; FilterJobDescription(IQueryable&lt;JobDescription&gt; jobdescriptions, Rule rule)
          {
              if (rule.field == "JobDescriptionID")
              {
                  int result;
                  if (!int.TryParse(rule.data, out result))
                      return jobdescriptions;
                  return jobdescriptions.Where(j =&gt; j.JobDescriptionID == Convert.ToInt32(rule.data));
  
              }
  
  // Similar Statements
  
              return jobdescriptions;
          }
  
  
  
  private IQueryable&lt;JobDescription&gt; orderJobDescription(IQueryable&lt;JobDescription&gt; jobdescriptions, string sortColumn, string sortOrder)
          {
              if (sortColumn == "JobDescriptionID")
                  return (sortOrder == "desc") ? jobdescriptions.OrderByDescending(j =&gt; j.JobDescriptionID) : jobdescriptions.OrderBy(j =&gt; j.JobDescriptionID);
  
              return jobdescriptions;
          }
  </code></pre>