title: Entity Framework Core CompileAsyncQuery syntax to do a query returning a list?
body: <p>Documentation and examples online about compiled async queries are kinda sparse, so I might as well ask for guidance here.</p>
  <p>Let's say I have a repository pattern method like this to query all entries in a table:</p>
  <pre class="lang-cs prettyprint-override"><code>public async Task&lt;List&lt;ProgramSchedule&gt;&gt; GetAllProgramsScheduledList()
  {
      using (var context = new MyDataContext(_dbOptions))
      {
          context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
          return await context.ProgramsScheduledLists.ToListAsync();
      }
  }
  </code></pre>
  <p>This works fine.</p>
  <p>Now I want to do the same, but with an async <a href="https://docs.microsoft.com/en-us/ef/core/performance/advanced-performance-topics?tabs=with-di%2Cwith-constant#compiled-queries" rel="nofollow noreferrer">compiled query</a>.</p>
  <p>One way I managed to get it to compile is with this syntax:</p>
  <pre class="lang-cs prettyprint-override"><code>static readonly Func&lt;MyDataContext, Task&lt;List&lt;ProgramSchedule&gt;&gt;&gt; GetAllProgramsScheduledListQuery;
  
  static ProgramsScheduledListRepository()
  {
      GetAllProgramsScheduledListQuery = EF.CompileAsyncQuery&lt;MyDataContext, List&lt;ProgramSchedule&gt;&gt;(t =&gt; t.ProgramsScheduledLists.ToList());
  }
  
  public async Task&lt;List&lt;ProgramSchedule&gt;&gt; GetAllProgramsScheduledList()
  {
      using (var context = new MyDataContext(_dbOptions))
      {
          context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
          return await GetAllProgramsScheduledListQuery(context);
      }
  }
  </code></pre>
  <p>But then on runtime this exception get thrown:</p>
  <pre><code>System.ArgumentException: Expression of type 'System.Collections.Generic.List`1[Model.Scheduling.ProgramSchedule]' cannot be used for return type 'System.Threading.Tasks.Task`1[System.Collections.Generic.List`1[Model.Scheduling.ProgramSchedule]]'
  </code></pre>
  <p>The weird part is that if I use any other operator (for example SingleOrDefault), it works fine. It only have problem returning List.</p>
  <p>Why?</p>