title: Internal Server error when using ToListAsync() or CountAsync()
body: <p>I am using this code to return  a list of objects in an Api:</p>
  
  <pre><code> [HttpGet("/api/product")]
  public async Task&lt;QueryResultResource&lt;PositionResource&gt;&gt; GetProducts(JobQueryResource queryObjResource)
  {
      var jobs = await context.Job.ToListAsync();
  
      var projects = await context.Project.ToListAsync();
  
      var volunteerships = await context.Volunteership.ToListAsync();
  
      var internships = await context.Internship.ToListAsync();
  
      var products1 = mapper.Map&lt;IEnumerable&lt;Job&gt;, IEnumerable&lt;PositionResource&gt;&gt;(jobs);
      foreach (var p in products1)
          p.ProductType = "Job";
  
      var products2 = mapper.Map&lt;IEnumerable&lt;Project&gt;, IEnumerable&lt;PositionResource&gt;&gt;(projects);
      foreach (var p in products2)
          p.ProductType = "Project";
  
      var products3 = mapper.Map&lt;IEnumerable&lt;Volunteership&gt;, IEnumerable&lt;PositionResource&gt;&gt;(volunteerships);
      foreach (var p in products3)
          p.ProductType = "Volunteership";
  
      var products4 = mapper.Map&lt;IEnumerable&lt;Internship&gt;, IEnumerable&lt;PositionResource&gt;&gt;(internships);
      foreach (var p in products4)
          p.ProductType = "Internship";
  
      var products = products1.Concat(products2).Concat(products3).Concat(products4).AsQueryable();
      products = products.OrderByDescending(x =&gt; x.CreationDate);
      products = products.Where(x =&gt; x.IsActive == true).AsQueryable();
  
  
      var queryObj = mapper.Map&lt;JobQueryResource, JobQuery&gt;(queryObjResource);
  
      var result = new QueryResult&lt;PositionResource&gt;();
  
  
      var columnsMap = new Dictionary&lt;string, Expression&lt;Func&lt;PositionResource, object&gt;&gt;&gt;()
      {
          ["title"] = j =&gt; j.Title,
          ["city"] = j =&gt; j.City,
          ["Type"] = j =&gt; j.Type,
          ["Industry"] = j =&gt; j.Industry
      };
  
  
      products = products.ApplyOrdering(queryObj, columnsMap).AsQueryable();
  
      result.TotalItems = await products.CountAsync();
  
      products = products.ApplyPaging(queryObj);
  
      result.Items = await products.ToListAsync();
  
      return mapper.Map&lt;QueryResult&lt;PositionResource&gt;, QueryResultResource&lt;PositionResource&gt;&gt;(result);
  
  }
  </code></pre>
  
  <p>I`m getting internal server error. I removed the await keyword and used Count() and ToList() for  </p>
  
  <pre><code> result.TotalItems = await products.CountAsync();
  ...
  result.Items = await products.ToListAsync();
  </code></pre>
  
  <p>It worked with no errors and i don`t understand why.</p>
  
  <p>Maybe it is one of the steps before that is generating the problem?</p>